Forum Moderators: coopster
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.
---------
PS: the Internet is full of examples like:
<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>
The problem is that somebody has to push the SUBMIT button after the data is filled in. Can this be done automatically? I mean without the SUBMIT button?
[edited by: Monitor at 12:06 am (utc) on Nov. 16, 2008]
This will raise way too many problems like Windows firewall & co.
This is why I choose POST. Seems tho the very "light" and won't disturb the user with firewall configuration, setting/forwarding ports, etc.
Thanks for the "Handling file uploads" link.
Seems to bee what I need.
From Windows, just make a call to:
http://www.example.com/submit.php?data=#*$!#*$!#*$!
(Where #*$!#*$!X is a base64 encoded binary string)
In PHP:
<?php
if ($_GET['data'])
{
if ($data=base64_decode($_GET['data'])
file_put_contents("saved_data",$data);
}
?> Be careful with this; by default an Apache server will only accept 8190 bytes of data in this way. The LimitRequestLine directive allows you to increase this if required.
The way around the length limit is to use POST, you can handle the POST data in much the same way as the GET data in my example above. It becomes more complex from your Windows application.
From Windows, you will need to open a socket and write the POST data directly to the server. What language will you use there?
I am using Delphi. I can already GET and POST messages with Delphi. This is no problem.
I want to send just a very small package. If it is possible, I want to send this data package without having my program blocked by the anti-virus/firewall or without forcing the user to to enter any Internet settings (IP, port,etc).
In this perspective, which method is more "lighter"? GET or POST ?
Thanks
[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?
if($_POST){
$str = '';
foreach($_POST as $P=>$p){
$str .= "$P => $p\r\n";
}
$str .= "====================\r\n";
$f = fopen('post.txt', 'a+');
fwrite($f, $str);
fclose($f);
print('POST request saved to disk as post.txt<br>');
}
else { print('No POST received!'); }