Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Thread: How can I send a bitmap to a php file?

  1. #1
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default How can I send a bitmap to a php file?

    I need to use SCAR with a php file to take a bitmap saved on my computer and save it to a .bmp file on my hosting site where the php file is.

    This should be possible because in SCAR you can do
    SCAR Code:
    program New;

    var
      Source: string;
      FileNumber: integer;
      Client: integer;
     
    begin
      FileNumber:= OpenFile('Path.bmp', false);
      ReadFileString(FileNumber, Source, FileSize(FileNumber));
      CloseFile(FileNumber);
      FileNumber:= RewriteFile('Path2.bmp', false);
      WriteFileString(FileNumber, Source);
      CloseFile(FileNumber);
    end.
    It will take the image in Path.bmp and copy it to a new bitmap file, Path2.bmp.

    So I figured this would work-
    SCAR Code:
    program New;

    var
      Source: string;
      FileNumber: integer;
      Client: integer;
     
    begin
      FileNumber:= OpenFile('Path.bmp', false);
      ReadFileString(FileNumber, Source, FileSize(FileNumber));
      CloseFile(FileNumber);
      Client:= InitializeHTTPClient(true, true);
      AddPostVariable(Client, 'pic', Source);
      PostHTTPPageEx(Client, 'http://yoursite.php');
    end.
    It takes that same bmp information but sends it to the php file.
    The php source is
    PHP Code:
    <?php

      $pic 
    $_POST['pic'];
      if (
    $pic <> ''
      {
        
    $handle fopen('pic.bmp''w');
        
    fwrite($handle$pic);
        
    fclose($handle);
      }

    ?>
    It works as far as sending it there and the file pic.bmp gets written.
    But not with the same information I sent to it.
    The crazy little chars that make up a bmp file can't be sent from SCAR to a php file.
    No matter what picture I send, it writes BMZ9 to the bmp file.

    So is there any way to do this?
    I don't have to use php, I'm just looking for any way possible to write a bmp file on the web from SCAR.

  2. #2
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    couldn't you have it like.. open paint then paste the picture then upload that to a site? (sorry.. don't think that's what you want.. but I couldn't understand it =X)

  3. #3
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Something like that but done in code.
    It isn't supposed to use mouse movements or key presses.
    It sends the information of a bitmap to the web, and that information is saved as a bitmap file, which can then be viewed by anyone from wherever it was saved.

  4. #4
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    and are you wanting to get the picture of it or the bitmap? (like 1835693825y1987235tsdhgaiu2e9+
    24htoung2ng031iugb1oiygbr

    stuff..)

  5. #5
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    If you do
    SCAR Code:
    FileNumber:= OpenFile('Path.bmp', false);
      ReadFileString(FileNumber, Source, FileSize(FileNumber));
      CloseFile(FileNumber);
    you will have the coding that makes up the bitmap in the variable "Source".
    It is different looking than when you do something like
    SCAR Code:
    bmp := BitmapFromString(11, 12, 'beNr79unNyxt0Qy+fX31y/9zDu' +
           '6ce3DmJjOAKgLLPHl6omrpCNbyZwaYEjuAKHt07DZRV92099/w/Mk' +
           'JWANS758o3NARXALQdaOCuy193Xf72BwR+QxCyCUAF2y982XHxy69' +
           'fP+EITcGWs5+3nvv848c3OEJTsPH0JyD69u0zHKEpWHviw9rjH799' +
           '+wRFAA6sR7w=');
    Because SCAR reads it different.
    It looks like
    SCAR Code:
    BMZ9     6   (   &#8482;  Ó$9
    ÿ  ÿ  ÿ  ÿ  ÿ  ÿ
    And a bunch of weird chars.

  6. #6
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    yeah, but what I'm asking is do you want the bmp like

    SCAR Code:
    bmp := BitmapFromString(11, 12, 'beNr79unNyxt0Qy+fX31y/9zDu' +
           '6ce3DmJjOAKgLLPHl6omrpCNbyZwaYEjuAKHt07DZRV92099/w/Mk' +
           'JWANS758o3NARXALQdaOCuy193Xf72BwR+QxCyCUAF2y982XHxy69' +
           'fP+EITcGWs5+3nvv848c3OEJTsPH0JyD69u0zHKEpWHviw9rjH799' +
           '+wRFAA6sR7w=');

    or the picture of that?

  7. #7
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I don't understand what you mean.
    But if this helps any, the script won't use a single thing that looks like
    SCAR Code:
    bmp := BitmapFromString(11, 12, 'beNr79unNyxt0Qy+fX31y/9zDu' +
           '6ce3DmJjOAKgLLPHl6omrpCNbyZwaYEjuAKHt07DZRV92099/w/Mk' +
           'JWANS758o3NARXALQdaOCuy193Xf72BwR+QxCyCUAF2y982XHxy69' +
           'fP+EITcGWs5+3nvv848c3OEJTsPH0JyD69u0zHKEpWHviw9rjH799' +
           '+wRFAA6sR7w=');
    It just gets the information in a bitmap and sends it.
    That pretty much sums it up.

  8. #8
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ok, you want
    SCAR Code:
    bmp := BitmapFromString(11, 12, 'beNr79unNyxt0Qy+fX31y/9zDu' +
           '6ce3DmJjOAKgLLPHl6omrpCNbyZwaYEjuAKHt07DZRV92099/w/Mk' +
           'JWANS758o3NARXALQdaOCuy193Xf72BwR+QxCyCUAF2y982XHxy69' +
           'fP+EITcGWs5+3nvv848c3OEJTsPH0JyD69u0zHKEpWHviw9rjH799' +
           '+wRFAA6sR7w=');

    to be sent to your website right?

    what I thought you meant was you want it to send a picture to your webby.. like convert the bitmapfromstring to a picture then send the picture

    if you want the
    SCAR Code:
    bmp := BitmapFromString(11, 12, 'beNr79unNyxt0Qy+fX31y/9zDu' +
           '6ce3DmJjOAKgLLPHl6omrpCNbyZwaYEjuAKHt07DZRV92099/w/Mk' +
           'JWANS758o3NARXALQdaOCuy193Xf72BwR+QxCyCUAF2y982XHxy69' +
           'fP+EITcGWs5+3nvv848c3OEJTsPH0JyD69u0zHKEpWHviw9rjH799' +
           '+wRFAA6sR7w=');

    copy and paste it into a text file, send the file to your webby..

    I hope that's what you mean =X

  9. #9
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    No
    But if this helps any, the script won't use a single thing that looks like
    BitmapFromString won't do anything for this.
    That is just used for SCAR.
    It reads the bitmap file to get the information.

  10. #10
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I'm really confused.. :'(

    you think you could tell me it in terms an idiot would understand?

  11. #11
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SCAR does mess up the string encoding - looking at them side by side in Notepad++ and SCAR, I think the problem is that SCAR treats all of the various header bytes (SOH, NUL, CAN) as 'unknown' and probably assigns some strange value to them, which corrupts the file when it is sent over the 'net.
    If you really want to, you could use cURL (even in a plugin), as it supports multi-part POST (i.e, file upload).

    EDIT: P.S, to those who are confused, if I'm reading this right, he wants to read a local file in SCAR, then POST it to his webpage which will save it on the server.

  12. #12
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by A G E N T View Post
    EDIT: P.S, to those who are confused, if I'm reading this right, he wants to read a local file in SCAR, then POST it to his webpage which will save it on the server.
    so couldn't you just copy and paste the stuff instead of saving the file? or save the file as .txt then manually paste in scar

  13. #13
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Agent has the right idea.
    I will try to explain it the best I can.

    You have a picture on your computer.
    Let's say it is called picture.bmp
    You can get the coding of that picture by reading the file with SCAR.
    You put that coding into a variable called Source.
    You send that variable to the web.
    It takes that information and writes it to a file.
    Let's say that file is www.thesite.com/picture2.bmp
    Now your picture, picture.bmp, is available to be seen by anyone at www.thesite.com/picture.bmp
    It's like uploading a picture on photobucket or something I guess, but it has to be done with coding.

  14. #14
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    oh I get it now..

    well one more thing..

    you want to do this

    BitmapToString

    load the string to the webby

    BitmapFromString

    so it will show the pic..

    right?

    and you will somehow run scar on the webby? >.>

  15. #15
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No...
    He wants to take a file from his computer, and load it in SCAR in a way that it can be sent with regular HTTP POST (i.e, as a string).
    He sends the string to his webpage, which saves it as a picture file, but the problem is that SCAR doesn't encode the header bytes properly, so the data is not sent correctly.

    EDIT:
    One more thing I can think of, you might try urlencoding the data before you send it.

  16. #16
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    oh ok

    I dunno then :\

  17. #17
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I think SCAR actually does encode it correctly and keep the string the way it is supposed to be, because you can get the information from your picture using SCAR and instead of sending it to a picture file on the web, send it to a picture file on your computer.
    Just like in the example I posted in the first post, it does work.
    But something about my php file getting the variable, it then turns it into pretty much nothing.

  18. #18
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Hey, 99_: He wants to make a code that uploads a bitmap from your computer to the internet, like imageshack.us does but done in scar.

  19. #19
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    couldnt you put more of the code on your server and do as little as possible in SCAR? by just sending the path with SCAR and having your php/perl script upload it to the server?
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  20. #20
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yeah, seems you're right - SCAR is encoding it fine, but it gets garbled during the transmission... Since I didn't feel like making a url-encode function, I did it this way (easy).
    Take each character, encode with ord(), then PHP end will decode with chr().
    SCAR Code:
    program New;

    var
      Source : string;
      FileNumber, i: integer;
      Client: integer;

    begin
      FileNumber:= OpenFile('C:\bmp.bmp', false);
      ReadFileString(FileNumber, Source, FileSize(FileNumber));
      CloseFile(FileNumber);
      Client := InitializeHTTPClient(false, false);
      for i := 1 to length(source)-1 do
      begin
        AddPOSTVariable(Client, IntToStr(i), inttostr(ord(Source[i])));
      end;
      POSTHTTPPageEx(Client, 'http://127.0.0.1/scarfile.php');
    end.

    PHP Code:
    <?PHP 
        $s 
    "";
        foreach(
    $_POST as $value)
        {
            
    $s .= chr($value);
        }
        
    file_put_contents("./up.bmp"$s);
    ?>
    Of course you might want to add more security so people don't go uploading nasty things to your server...

  21. #21
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    That actually worked, but there is still a problem.
    It takes over 5 minutes to send the whole computer screen.
    It can do a 30 X 30 bitmap in a few seconds though.
    But what I'm using this for will need to use a bitmap almost the size of the screen and it will be doing it over and over.
    I think there is a way to send it all at once, or at least in chunks, instead of every byte one by one.

    couldnt you put more of the code on your server and do as little as possible in SCAR? by just sending the path with SCAR and having your php/perl script upload it to the server?
    That would be ideal, but I have learned only the very basics of php and I don't know perl.
    Actually if that's possible I will learn how and do it that way.

  22. #22
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    perl - you need perl installed on your server.
    you'll need to change the 1024 *5000 if you want to upload things bigger than 5MB
    Code:
    #!/usr/bin/perl -wT
    
    use strict;
    use CGI;
    use CGI::Carp qw ( fatalsToBrowser );
    use File::Basename;
    
    $CGI::POST_MAX = 1024 * 5000;
    my $safe_filename_characters = "a-zA-Z0-9_.-";
    my $upload_dir = "/home/mywebsite/htdocs/upload";
    
    my $query = new CGI;
    my $filename = $query->param("photo");
    my $email_address = $query->param("email_address");
    
    if ( !$filename )
    {
     print $query->header ( );
     print "There was a problem uploading your photo (try a smaller file).";
     exit;
    }
    
    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
    $filename = $name . $extension;
    $filename =~ tr/ /_/;
    $filename =~ s/[^$safe_filename_characters]//g;
    
    if ( $filename =~ /^([$safe_filename_characters]+)$/ )
    {
     $filename = $1;
    }
    else
    {
     die "Filename contains invalid characters";
    }
    
    my $upload_filehandle = $query->upload("photo");
    
    open ( UPLOADFILE, ">$upload_dir/$filename" ) or die "$!";
    binmode UPLOADFILE;
    
    while ( <$upload_filehandle> )
    {
     print UPLOADFILE;
    }
    
    close UPLOADFILE;
    and i cannot find a way to do it in php without having a form, and user interaction.

    EDIT: JK, i dont think that will do it. I think that prompts the user . Nvm, i dont think its possible to do it automatically.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  23. #23
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I think most methods of uploading images require some sort of user interaction.
    Uggghh.
    I still know it can be done though.

  24. #24
    Join Date
    Feb 2007
    Location
    Toronto, Ontario, Canada
    Posts
    586
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    This is the only way I could think of to encode long strings - it doesn't really have to be split to chunks, but it will avoid heavy lag on larger strings... Of course it's still a lot slower than a plugin, but it can do 500x500px bitmap in about 30s.
    SCAR end:
    SCAR Code:
    program New;
    const
      LeastChunks = 10; //number of chunks to try splitting to -
                        //script will find a number that divides cleanly
    var
      Source, Enc : string;
      FileNumber, i, l, chunks : integer;
      Client: integer;
     
    function inttohex(i:longint):string;
    var
      n:longint;
      s, lookup :string;
    begin
      lookup := '0123456789ABCDEF';
      n:=i;
      if i=0 then s:='00' else s:='';
      while n>0 do
        begin
          s:=lookup[n mod 16+1]+s;
          n:=n div 16;
        end;
      while length(s)<2 do s:='0'+s;
      result:=s;
    end;

    function StrToHex(str:string):String;
    var
      i : integer;
    begin
      Result := '';
      for i := 1 to length(str) do
      begin
        Result := Result + inttohex(ord(str[i]));
      end;
    end;

    begin
      FileNumber:= OpenFile('C:\insane.bmp', false);
      ReadFileString(FileNumber, Source, FileSize(FileNumber));
      CloseFile(FileNumber);
      l := length(source);
      for i := leastchunks to 9999 do
      begin
        chunks := i;
        if (l mod chunks) = 0 then Break;
      end;
      Client := InitializeHTTPClient(false, false);
      for i := 1 to chunks do
        Enc := Enc + StrToHex(copy(Source, (((l div chunks) * i) - (l div chunks))+1, (l div chunks)));
       
      AddPOSTVariable(Client, 'enc', Enc);
      POSTHTTPPageEx(Client, 'http://127.0.0.1/scarfile.php');
    end.
    PHP End:
    PHP Code:
    <?PHP 
    function hexstr($hex)
    {
        
    $string="";
        for (
    $i=0;$i<strlen($hex)-1;$i+=2)
            
    $string.=chr(hexdec($hex[$i].$hex[$i+1]));
        return 
    $string;
    }
        
    $s "";
        foreach(
    $_POST as $value)
        {
            echo 
    $value;
            
    $s .= hexstr($value);
        }
        
    file_put_contents("./up.bmp"$s);
    ?>

  25. #25
    Join Date
    Jan 2007
    Location
    Tennessee
    Posts
    642
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    I tried that one and everything ran but I didn't end up with a picture somehow.
    And I've tried to get it to work all sorts of ways.

    Also if I can't get it down to about 1 second per pic or less I don't think I'll be able to do what I'm working on.

    I appreciate the help though, I'm getting somewhere.
    repped

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. type send not send keys in vb
    By Noob King in forum C#/Visual Basic Help and Tutorials
    Replies: 5
    Last Post: 10-23-2008, 09:14 PM
  2. How to send the key esc.
    By Derek- in forum OSR Help
    Replies: 3
    Last Post: 12-23-2007, 03:37 AM
  3. Find Bitmap in Bitmap file
    By fORCE_wORKS in forum RS3 Outdated / Broken Scripts
    Replies: 8
    Last Post: 12-13-2007, 11:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •