ajax - Copying file uploaded vai PHP's HTTP Get in PHP 4 -
i have been working on adding functionality site written in php 4.4.9. it's not in budget port site php5, don't suggest it. (although needs badly). problem facing how copy binary data request file location on server. code written support method follows:
function save($path) { $input = fopen("php://input", "r"); $temp = tmpfile(); $realsize = stream_copy_to_stream($input, $temp); fclose($input); if ($realsize != $this->getsize()){ return false; } $target = fopen($path, "w"); fseek($temp, 0, seek_set); stream_copy_to_stream($temp, $target); fclose($target); }
the problem having funciton stream_copy_to_stream
supported in php 5. here have far, seems create files 8k in size , i'm not sure why. should, in theory, allow 20m.
function save($path) { $input = fopen("php://input", "rb"); $temp = tmpfile(); fwrite($temp, fread($input, 20971520)); fclose($input); $target = fopen($path, "w"); fseek($temp, 0, seek_set); #stream_copy_to_stream($temp, $target); fwrite($target, fread($temp, 20971520)); fclose($target); echo $path; return true; }
i removed size check because couldn't figure way filesize when reading. appreciated on this. have been racking brain literally hours , know there out there, on stackoverflow, can answer question easily.
thanks in advance!
also, submitting data via to allow multiple file uploads progress bars, etc.
i came across thread looking answer exact same problem.
know post old putting answer here else looking.
close.
fread takes 8192 byte chunks out of stream @ time. have loop through until sees end of file.
function save($path) { $input = fopen("php://input", "rb"); $temp = tmpfile(); while(!feof($input)) fwrite($temp, fread($input, 8192)); //fwrite($temp, fread($input, 20971520)); fclose($input); $target = fopen($path, "w"); fseek($temp, 0, seek_set); #stream_copy_to_stream($temp, $target); while(!feof($temp)) fwrite($target, fread($temp, 8192)); fclose($target); echo $path; return true; }
Comments
Post a Comment