php - stream_copy_to_stream() always returns 0 -


i'm using fine-uploader php , wrong happened. when use stream_copy_to_stream() in backend, returns 0.

here's code in backend:

private function upload_file($file_name, $tmp_name) {     $result = array(             'is_successful' => true,             'extra_message' => ''         );      $target_path = $this->get_target_file_path($file_name, $tmp_name);     move_uploaded_file($tmp_name, $target_path);     $result['is_successful'] = $this->handle_upload_request($target_path);     if ( $result['is_successful'] ) {         $result['extra_message'] = $target_path;     } else {         $result['extra_message'] = 'unknown error occured.<br />';     }      return $result; }  private function handle_upload_request($path) {     $input = fopen("php://input", "r");     $temp = tmpfile();     $real_size = stream_copy_to_stream($input, $temp);     fclose($input);      echo $real_size;     if ($real_size != $this->get_size()){                     return false;     }      $target = fopen($path, "w");             fseek($temp, 0, seek_set);     stream_copy_to_stream($temp, $target);     fclose($target);      return true; } 

however, $real_size equal 0. strangely, file can uploaded sometimes, not.

i think maybe it's due permission in linux. because found when uploaded file, mod of file 644(but think 644 enough). , problem exists in windows.

what's wrong it?

you should not using php://input. php://input used access raw request body. empty multipart encoded requests. upload requests sent fine uploader multipart encoded default. instead, should grab file associated request using $_files superglobal. there functional php example demonstrate , more in fine uploader server github repo.

if insist on writing own php code handle requests, need read traditional server-side documentation fine uploader first, tells upload requests multipart encoded default. set default in order make bit easier handle upload requests cross-browser, since need send files in mpe request ie9 , older anyway, since ie9 , older not support uploading files via ajax requests (xhr2).


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -