打开php.php发现在文件头部说明该文件使用同时在文件定义三个类用来分别处理XMLHttpRequest、FormPost、BasicPost方式文件服务器端处理.在文件顶部注释中: /**************************************** Example of how to use this uploader class... You can uncomment the following lines (minus the require) to use hese as your defaults.
// list of valid extensions, ex. array("jpeg", "xml", "bmp") $allowedExtensions = array(); // max file size in bytes $sizeLimit = 10 * 1024 * 1024; //the input name set in the javascript $inputName = 'qqfile'
require('valums-file-uploader/server/php.php'); $uploader = new qqFileUploader($allowedExtensions, $sizeLimit, $inputName);
// Call handleUpload() with the name of the folder, relative to PHP's getcwd() $result = $uploader->handleUpload('uploads/');
// to pass data through iframe you will need to encode all html tags header("Content-Type: text/plain"); echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
/** * Handle the 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 were uploaded.'); }
$size = $this->file->getSize();
if ($size == 0) { return array('error' => 'File is empty'); }
if ($size > $this->sizeLimit) { return array('error' => 'File is too large'); }
$pathinfo = pathinfo($this->file->getName()); $filename = $pathinfo['filename']; //$filename = md5(uniqid()); $ext = @$pathinfo['extension'];// hide notices if extension is empty
if($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)){ $these = implode(', ', $this->allowedExtensions); return array('error' => 'File has an invalid extension, it should be one of '. $these . '.'); }
$ext = ($ext == '') ? $ext : '.' . $ext;
if(!$replaceOldFile){ /// don't overwrite previous files that were 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 was cancelled, or server error encountered'); }
在上传操作过程发信很多出现“increase post_max_size and upload_max_filesize to 10M”错误,其实针对这个问题.主要是上传文件配置超过php环境默认的2M.需要在php.ini文件中把post_max_size和upload_max_filesize两项的值改到10M以上,然后重启Apache即可.或是参考Php官网针对配置说明 修改php.ini配置文件. 至此整个Fine Uploader配置流程已经全部完成.点击选择文件时.会如下效果: