stream - Form boundaries and writing php://input to a file in php -


so want users able upload big files without having worry post max size values. alternative using put , send file raw data. when using jquery can this:

var data = new formdata();   jquery.each($('#file_upload')[0].files, function(i, file) {   data.append('file-'+i, file); }); $.ajax({   url: 'upload.php?filename=test.pdf',   data: data,   cache: false,   contenttype: false,   processdata: false,   type: 'put', }); 

in php can this:

$f = fopen($_get['filename'], "w"); $s = fopen("php://input", "r");  while($kb = fread($s, 1024)) {    fwrite($f, $kb, 1024);  } fclose($f); fclose($s); header("http/1.1 201 created"); 

i not doing:

$client_data = file_get_contents("php://input"); 

since putting whole file variable surely fill memory when uploading huge files.

the thing cannot figure out how write file data without form boundaries. right writes @ top of file this:

------webkitformboundaryvz0zghlgxbocuvqg content-disposition: form-data; name="file-0"; filename="somename.pdf" content-type: application/pdf 

and @ bottom this:

------webkitformboundaryvz0zghlgxbocuvqg--     

so need parse data. need read whole data stream memory , large video files don't want that. did read maybe creating php://temp stream. no luck yet that. how can write content file, without boundary header? , without first pumping data variable?

maybe combination of fgets stop reading @ newline , checking boundaries:

while($kb = fgets($s, 1024)) {      if(strpos($kb, '------') === false) //or !== 0 first position     {         fwrite($f, $kb, 1024);      } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -