打开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);
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'); }
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn