fine-uploader PHP Server Side Merge -


i'm been experimenting fine uploader. interested in chunking , resume features, i'm experiencing difficulties putting files server side;

what i've found have allow blank file extension on server side allow upload of chunks, otherwise upload fail unknown file type. uploads chunks fine file names such "blob" , "blob63" (no file extension) not merge them @ completion of upload.

any or pointers appreciated.

$('#edit-file-uploader').fineuploader({             request: {                 endpoint: 'upload.php'             },             multiple: false,             validation:{                 allowedextentions: ['stl', 'obj', '3ds', 'zpr', 'zip'],                 sizelimit: 104857600  // 100mb * 1024 (kb) * 1024 (bytes)             },             text: {                 uploadbutton: 'select file'             },             autoupload: false,              chunking: {               enabled: true             },             callbacks: {                  oncomplete: function(id, filename, responsejson) {                   if (responsejson.success) {                      /** code here **??                   }            }      }); 

and server side script (php):

// list of valid extensions, ex. array("stl", "xml", "bmp") $allowedextensions = array("stl", ""); // max file size in bytes $sizelimit = null;  $uploader = new qqfileuploader($allowedextensions, $sizelimit);  // call handleupload() name of folder, relative php's getcwd() $result = $uploader->handleupload('uploads/');  // pass data through iframe need encode html tags echo htmlspecialchars(json_encode($result), ent_noquotes);  /******************************************/    /**  * handle file uploads via xmlhttprequest  */ class qquploadedfilexhr {     /**      * save file specified path      * @return boolean true on success      */     public 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);          return true;     }      /**      * original filename      * @return string filename      */     public function getname() {         return $_get['qqfile'];     }      /**      * file size      * @return integer file-size in byte      */     public function getsize() {         if (isset($_server["content_length"])){             return (int)$_server["content_length"];                     } else {             throw new exception('getting content length not supported.');         }           }    }  /**  * handle file uploads via regular form post (uses $_files array)  */ class qquploadedfileform {      /**      * save file specified path      * @return boolean true on success      */     public function save($path) {         return move_uploaded_file($_files['qqfile']['tmp_name'], $path);     }      /**      * original filename      * @return string filename      */     public function getname() {         return $_files['qqfile']['name'];     }      /**      * file size      * @return integer file-size in byte      */     public function getsize() {         return $_files['qqfile']['size'];     } }  /**  * class encapsulates file-upload internals  */ class qqfileuploader {     private $allowedextensions;     private $sizelimit;     private $file;     private $uploadname;      /**      * @param array $allowedextensions; defaults empty array      * @param int $sizelimit; defaults server's upload_max_filesize setting      */     function __construct(array $allowedextensions = null, $sizelimit = null){         if($allowedextensions===null) {             $allowedextensions = array();         }         if($sizelimit===null) {             $sizelimit = $this->tobytes(ini_get('upload_max_filesize'));         }          $allowedextensions = array_map("strtolower", $allowedextensions);          $this->allowedextensions = $allowedextensions;                 $this->sizelimit = $sizelimit;          $this->checkserversettings();                 if(!isset($_server['content_type'])) {             $this->file = false;             } else if (strpos(strtolower($_server['content_type']), 'multipart/') === 0) {             $this->file = new qquploadedfileform();         } else {             $this->file = new qquploadedfilexhr();         }     }      /**      * name of uploaded file      * @return string      */     public function getuploadname(){         if( isset( $this->uploadname ) )             return $this->uploadname;     }      /**      * original filename      * @return string filename      */     public function getname(){         if ($this->file)             return $this->file->getname();     }      /**      * internal function checks if server's may sizes match      * object's maximum size uploads      */     private function checkserversettings(){                 $postsize = $this->tobytes(ini_get('post_max_size'));         $uploadsize = $this->tobytes(ini_get('upload_max_filesize'));                  if ($postsize < $this->sizelimit || $uploadsize < $this->sizelimit){             $size = max(1, $this->sizelimit / 1024 / 1024) . 'm';                          die(json_encode(array('error'=>'increase post_max_size , upload_max_filesize ' . $size)));             }             }      /**      * convert given size units bytes      * @param string $str      */     private function tobytes($str){         $val = trim($str);         $last = strtolower($str[strlen($str)-1]);         switch($last) {             case 'g': $val *= 1024;             case 'm': $val *= 1024;             case 'k': $val *= 1024;                 }         return $val;     }      /**      * handle uploaded file      * @param string $uploaddirectory      * @param string $replaceoldfile=true      * @returns array('success'=>true) or array('error'=>'error message')      */     function handleupload($uploaddirectory, $replaceoldfile = false){         if (!is_writable($uploaddirectory)){             return array('error' => "server error. upload directory isn't writable.");         }          if (!$this->file){             return array('error' => 'no files uploaded.');         }          $size = $this->file->getsize();          if ($size == 0) {             return array('error' => 'file empty');         }          if ($size > $this->sizelimit) {             return array('error' => 'file large');         }          $pathinfo = pathinfo($this->file->getname());         $filename = $pathinfo['filename'];         //$filename = md5(uniqid());         $ext = @$pathinfo['extension'];        // hide notices if extension empty          if($this->allowedextensions && !in_array(strtolower($ext), $this->allowedextensions)){             $these = implode(', ', $this->allowedextensions);             return array('error' => 'file has invalid extension, should 1 of '. $these . '.');         }          $ext = ($ext == '') ? $ext : '.' . $ext;          if(!$replaceoldfile){             /// don't overwrite previous files uploaded             while (file_exists($uploaddirectory . directory_separator . $filename . $ext)) {                 $filename .= rand(10, 99);             }         }          $this->uploadname = $filename . $ext;          if ($this->file->save($uploaddirectory . directory_separator . $filename . $ext)){             return array('success'=>true);         } else {             return array('error'=> 'could not save uploaded file.' .                 'the upload cancelled, or server error encountered');         }      }     } 

in order handle chunked requests, must store each chunk separately in filesystem.
how name these chunks or store them you, suggest name them using uuid provided fine uploader , append part number parameter included each chunked request. after last chunk has been sent, combine chunks 1 file, proper name, , return standard success response described in fine uploader documentation. original name of file is, default, passed in qqfilename parameter each request. discussed in docs , blog.

it doesn't you've made attempt handle chunks server-side. there php example in widen/fine-uploader-server repo can use. also, documentation has "server-side" section explains how handle chunking in detail. i'm guessing did not read this. have look.) in widen/fine-uploader-server repo can use. also, documentation has "server-side" section explains how handle chunking in detail. i'm guessing did not read this. have look.

note that, starting fine uploader 3.8 (set release soon) able delegate server-side upload handling amazon s3, fine uploader provide tight integration s3 sends of files directly bucket browser without having worry constructing policy document, making rest api calls, handling responses s3, etc. mention using s3 means never have worry handling things chunked requests on server again.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -