Re: POST files with PHP
| From: | _lallous | Date: | Tue, 20 Nov 2001 11:16:37 +0000 |
| Subject: | Re: POST files with PHP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-75226@lists.php.net to get a copy of this message | ||
Never tried that, But i'm afraid that by reading a binary file like:
join('', file('binfile'))
will brake the file!
try using fopen('binfile', 'rb') and fread() and filesize()
good luck.
"Daniel Reichenbach" <daniel.reichenbach@pixum.com> wrote in message
news:000001c17111$02617a50$796010ac@danielmob...
> Hy,
>
> I'm trying to post image files to a php script with another php script.
> Don't ask why, it's a crazy project :)
> Now the file is around 28000 bytes but the post receiver only gets
> around
> 300 bytes. Has anybody experienced this behaviour?
>
> I use the following script:
>
> --- snap ---
> <?
> // the receiver of file
> $remote_page = "http://www.server.com/post.php";
>
> // the file to upload
> $file = "/var/www/test/dummy.jpg"; // the file location
> $con_type = "image/jpg"; // the file mime type
> $content_file = join("",file($file));
>
> // define boundary
> srand((double)microtime()*1000000);
> $boundary =
> "---------------------------".substr(md5(rand(0,32000)),0,10);
> $data = "--$boundary
> Content-Disposition: form-data; name=\"userfile\"; filename=\"$file\"
> Content-Type: $con_type
>
> $content_file"."--$boundary--\r\n\r\n";
> $msg =
> "POST $remote_page HTTP/1.0
> Content-Type: multipart/form-data; boundary=$boundary
> Content-Length: ".strlen($data)."\r\n\r\n";
>
> $f = fsockopen("www.server.com",80);
> fputs($f,$msg.$data);
> $result = fread($f,32000);
> fclose($f);
> print $result."\n<br>";
>
> ?>
> --- snap --
>
>