Page 1 of 1
I need to send binary data from a Windows app. to a web site
Posted: Sat Nov 15, 2008 5:54 pm
by bugmenot
I need to send binary data from a Windows application to a site. I am used with compiled programming but I don't know much PHP
Is it possible for a PHP script running on a Linux server to receive a package (binary string) of data of random size and store it to disk? Can anybody post a pseudo code (mock-up) PHP program for this so I can use it as starting point?
Thanks a lot.
Re: I need to send binary data from a Windows app. to a web site
Posted: Sat Nov 15, 2008 6:23 pm
by Eran
The php part would be pretty easy - depending on the method you choose to transport your data, most commonly using GET or POST headers:
Code: Select all
$filename = '/path/to/file.ext';
$data = $_POST['data'];
file_put_contents($filename,$data);
$_POST is an array of parameters sent with POST headers. Similarly $_GET would contain data sent with GET headers (simply as a parameter string through the address line). Those two arrays are
superglobal variables which are available always for a PHP script environment.
For binary data you most likely be using POST, or a specific input stream wrapper - see
this link for a complete list of those.
The more technical aspect of this would be in your application site, constructing the request (PHP being a web language, has plenty of ready-made ways to do this). Depending on your language of choice this could be very easy or just moderately easy

Re: I need to send binary data from a Windows app. to a web site
Posted: Sat Nov 15, 2008 6:30 pm
by bugmenot
Hi Pytrin.
I use Delphi and I can already send data (POST) to web server made (HTTP port 80) also in Delphi.
I "just" need to replace the Delphi web server with a PHP script. Pretty difficult when you know knowing about PHP
What I need is the PHP script that will receive the data (POST) and store it to disk.
I think I need something like this:
<form action="file.php" method="POST">
Your Name:
<input type="text" name="user_name_field" id="user_name_field">
<br />
<input type="submit" value="Enter My Name in DB">
</form>
...but without the SUBMIT button.
------------------
Delphi way

of POST-ing:
procedure THttpPostForm.PostButtonClick(Sender: TObject);
var Data : String;
begin
Data := 'FirstName=' + UrlEncode(Trim(FirstNameEdit.Text)) + '&' + 'LastName=' + UrlEncode(Trim(LastNameEdit.Text)) + '&' + 'Submit=Submit';
HttpCli1.SendStream := TMemoryStream.Create;
HttpCli1.SendStream.Write(Data[1], Length(Data));
HttpCli1.SendStream.Seek(0, 0);
HttpCli1.RcvdStream := TMemoryStream.Create;
HttpCli1.URL := Trim(ActionURLEdit.Text);
HttpCli1.PostAsync;
end;
Re: I need to send binary data from a Windows app. to a web site
Posted: Sat Nov 15, 2008 6:40 pm
by Eran
I think you misunderstood the flow a little - what you described is a form (or controls, whatever you want to call it). I already presented you with the script that can handle a POST request and save it into a file (yep, 3 lines - it's that simple). Of course it's completely barebones, with no checks or validation, but you should be able to take it from there.
For a more general knowledgebase you should get acquainted with the PHP manual, its an amazing resource -
http://www.php.net
If you have any more specific questions, we'll be happy to help.
Re: I need to send binary data from a Windows app. to a web site
Posted: Sat Nov 15, 2008 7:08 pm
by bugmenot
pytrin wrote:I think you misunderstood the flow a little - what you described is a form (or controls, whatever you want to call it). I already presented you with the script that can handle a POST request and save it into a file (yep, 3 lines - it's that simple).
If you have any more specific questions, we'll be happy to help.
Somebody pointed me to
http://us.php.net/manual/en/features.file-upload.php and I think I understand now your message now. I think I got the right direction now.
Thanks a lot.
By the way, among all web oriented programming languages, PHP rules!
Re: I need to send binary data from a Windows app. to a web site
Posted: Sun Nov 16, 2008 5:12 pm
by bugmenot
Ok. I started to build my first PHP program.
I don't think it will have more than 30 lines.

Re: I need to send binary data from a Windows app. to a web site
Posted: Sun Nov 16, 2008 7:32 pm
by bugmenot
I am advancing.
However, I need to debug the POST package I send from my windows app. I think it is not properly formated because I get this:
[16-Nov-2008 17:22:23] PHP Warning: Missing boundary in multipart/form-data POST data in Unknown on line 0
Where/how can I see the HTTP POST request that my app sends?
Re: I need to send binary data from a Windows app. to a web site
Posted: Sun Nov 16, 2008 8:05 pm
by Eran
Re: I need to send binary data from a Windows app. to a web site
Posted: Mon Nov 17, 2008 5:11 am
by bugmenot
The manual says:
However, the preferred method for accessing the raw POST data is php://input. $HTTP_RAW_POST_DATA is not available with enctype="multipart/form-data".
While my HTML form is:
Code: Select all
<form enctype="[color=#FF0000]multipart/form-data[/color]" action="http://www.DNABaser.com/1/index.php" method="POST">
Re: I need to send binary data from a Windows app. to a web site
Posted: Mon Nov 17, 2008 5:21 am
by Eran
Re: I need to send binary data from a Windows app. to a web site
Posted: Thu Nov 20, 2008 5:57 pm
by bugmenot
Problem solved. Thank you very much for help.