ajax - Why is php://input rejecting my large file uploads? -


i've been turing internet upside down in order chunked large file uploads work symfony2 application. in order simplify things i've made test program seperate rest of application. thing trying test if php://input can accept large file upload method described in article:

http://www.webiny.com/blog/2012/05/07/webiny-file-upload-with-html5-and-ajax-using-php-streams/

the way understand if user uploads large video file 2gb+ take 2gb+ ram on server , method in article cuts down 4096 bit per concurrent uploader. (i unsure how test ram usage on localhost server)

however when try upload large files browser waits second , 2 , posts 1kb videofile.

i have set high values php.ini settings.

here relevant part of php code:

     public function lastoppaction(request $request) {      $videofilename = (string)$request->request->get("filnavn");     $inputhandler = fopen("php://input", "rb");     $filehandler = fopen("videoer\\myfile.tmp", "wb") or die('fopen failed');;      while(true) { $buffer = fgets($inputhandler, 4096); if (strlen($buffer) == 0) {      fclose($inputhandler);     fclose($filehandler);             break; } fwrite($filehandler, $buffer) or die('fwrite failed');;     }      $url = $this->generateurl('largefile_navngi', array('filnavn' => $videofilename));      return $this->redirect($url); } public function navngiaction(request $request) {         $filnavn = $request->query->get('filnavn');         $sti = $this->container->getparameter('kernel.root_dir');         $websti = preg_replace('/app/','web',$sti,1);         print_r("filnavn: " . $filnavn);         rename($websti . "/videoer/myfile.tmp",$websti . "/videoer/" . $filnavn);         $url = $this->generateurl('largefile_index');         return $this->redirect($url); } 

the reason redirects in order rename recieve filename variable.

the ajax code in article linked above following difference:

xhr.open("post", url, false); using own localhost url. have tried true here. difference being works small files if have false in third argument.

with async true seems ever give 2 files original myfile.tmp fopen , 0kb file renames to. "filename.mp4".

what strange when ajax code runs:

xhr.onreadystatechange = function()                 {                     if(xhr.readystate == 4)                     {                         if(xhr.status == 200)                         {                             //alert("success");// process success                                                             alert("filnavn: " + filnavn);                         }else{                             // process error                                                             alert("status: " + xhr.status);                         }                     }                 }; 

status becomes 500 when small files 16 mb uploaded without other issues.

here twig file:

    <h1>test av å laste opp større filer</h1>     <form method="post" action="{{path('largefile_lastopp')}}">         <label>fil: </label>         <input type="file" name="fil" id="video" /><br /><br />          <input type="hidden" name="filnavn" id="filnavn" />          <input type="hidden" name="mimetype" id="mimetype" />          <input onclick="upload('video',0)" type="submit" name="submit" />      </form>      ::1 - - [10/jun/2015:15:41:36 +0200] "post /largefileupload/web/app_dev.php/lastopp http/1.1" 302 436 "http://localhost/largefileupload/web/app_dev.php/" "mozilla/5.0 (windows nt 6.2; wow64) applewebkit/537.36 (khtml, gecko) chrome/43.0.2357.81 safari/537.36" 

i think problem here client code reads whole file @ once, creates blob it. if try upload 1gb file, means browser requires @ least 2gb ram before ist sends first byte.

i imagine there might security measure prevent kind of memory (ab-)use.


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -