<?php
/**
* Do not use or reference this directly from your client-side code.
* Instead, this should be required via the endpoint.php or endpoint-cors.php
* file(s).
*/
class UploadHandler {
public $allowedExtensions = array();
public $sizeLimit = null;
public $inputName = 'qqfile';
public $chunksFolder = 'chunks';
public $chunksCleanupProbability = 0.001; // Once in 1000 requests on avg
public $chunksExpireIn = 604800; // One week
protected $uploadName;
/**
* Get the original filename
*/
public function getName(){
if (isset($_REQUEST['qqfilename']))
return $_REQUEST['qqfilename'];
if (isset($_FILES[$this->inputName]))
return $_FILES[$this->inputName]['name'];
}
public function getInitialFiles() {
$initialFiles = array();
for ($i = 0; $i < 5000; $i++) {
array_push($initialFiles, array("name" => "name" + $i, uuid => "uuid" + $i, thumbnailUrl => "/test/dev/handlers/vendor/fineuploader/php-traditional-server/fu.png"));
}
return $initialFiles;
}
/**
* Get the name of the uploaded file
*/
public function getUploadName(){
return $this->uploadName;
}
public function combineChunks($uploadDirectory, $name = null) {
$uuid = $_POST['qquuid'];
if ($name === null){
$name = $this->getName();
}
$targetFolder = $this->chunksFolder.DIRECTORY_SEPARATOR.$uuid;
$totalParts = isset($_REQUEST['qqtotalparts']) ? (int)$_REQUEST['qqtotalparts'] : 1;
$targetPath = join(DIRECTORY_SEPARATOR, array($uploadDirectory, $uuid, $name));
$this->uploadName = $name;
if (!file_exists($targetPath)){
mkdir(dirname($targetPath), 0777, true);
}
$target = fopen($targetPath, 'wb');
for ($i=0; $i<$totalParts; $i++){
$chunk = fopen($targetFolder.DIRECTORY_SEPARATOR.$i, "rb");
stream_copy_to_stream($chunk, $target);
fclose($chunk);
}
// Success
fclose($target);
for ($i=0; $i<$totalParts; $i++){
unlink($targetFolder.DIRECTORY_SEPARATOR.$i);
}
rmdir($targetFolder);
if (!is_null($this->sizeLimit) && filesize($targetPath) > $this->sizeLimit) {
unlink($targetPath);
http_response_code(413);
return array("success" => false, "uuid" => $uuid, "preventRetry" => true);
}
return array("success" => true, "uuid" => $uuid);
}
/**
* Process the upload.
* @param string $uploadDirectory Target directory.
* @param string $name Overwrites the name of the file.
*/
public function handleUpload($uploadDirectory, $name = null){
if (is_writable($this->chunksFolder) &&
1 == mt_rand(1, 1/$this->chunksCleanupProbability)){
// Run garbage collection
$this->cleanupChunks();
}
// Check that the max upload size specified in class configuration does not
// exceed size allowed by server config
if ($this->toBytes(ini_get('post_max_size')) < $this->sizeLimit ||
$this->toBytes(ini_get('upload_max_filesize')) < $this->sizeLimit){
$neededRequestSize = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
return array('error'=>"Server error. Increase post_max_size and upload_max_filesize to ".$neededRequestSize);
}
if ($this->isInaccessible($uploadDirectory)){
return array('error' => "Server error. Uploads directory isn't writable");
}
$type = $_SERVER['CONTENT_TYPE'];
if (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
$type = $_SERVER['HTTP_CONTENT_TYPE'];
}
if(!isset($type)) {
return array('error' => "No files were uploaded.");
} else if (strpos(strtolower($type), 'multipart/') !== 0){
return array('error' => "Server error. Not a multipart request. Please set forceMultipart to default value (true).");
}
// Get size and name
$file = $_FILES[$this->inputName];
$size = $file['size'];
if (isset($_REQUEST['qqtotalfilesize'])) {
$size = $_REQUEST['qqtotalfilesize'];
}
if ($name === null){
$name = $this->getName();
}
// check file error
if($file['error']) {
return array('error' => 'Upload Error #'.$file['error']);
}
// Validate name
if ($name === null || $name === ''){
return array('error' => 'File name empty.');
}
// Validate file size
if ($size == 0){
return array('error' => 'File is empty.');
}
if (!is_null($this->sizeLimit) && $size > $this->sizeLimit) {
return array('error' => 'File is too large.', 'preventRetry' => true);
}
// Validate file extension
$pathinfo = pathinfo($name);
$ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
if($this->allowedExtensions && !in_array(strtolower($ext), array_map("strtolower", $this->allowedExtensions))){
$these = implode(', ', $this->allowedExtensions);
return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
}
// Save a chunk
$totalParts = isset($_REQUEST['qqtotalparts']) ? (int)$_REQUEST['qqtotalparts'] : 1;
$uuid = $_REQUEST['qquuid'];
if ($totalParts > 1){
# chunked upload
$chunksFolder = $this->chunksFolder;
$partIndex = (int)$_REQUEST['qqpartindex'];
if (!is_writable($chunksFolder) && !is_executable($uploadDirectory)){
return array('error' => "Server error. Chunks directory isn't writable or executable.");
}
$targetFolder = $this->chunksFolder.DIRECTORY_SEPARATOR.$uuid;
if (!file_exists($targetFolder)){
mkdir($targetFolder, 0777, true);
}
$target = $targetFolder.'/'.$partIndex;
$success = move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $target);
return array("success" => true, "uuid" => $uuid);
}
else {
# non-chunked upload
$target = join(DIRECTORY_SEPARATOR, array($uploadDirectory, $uuid, $name));
if ($target){
$this->uploadName = basename($target);
if (!is_dir(dirname($target))){
mkdir(dirname($target), 0777, true);
}
if (move_uploaded_file($file['tmp_name'], $target)){
return array('success'=> true, "uuid" => $uuid);
}
}
return array('error'=> 'Could not save uploaded file.' .
'The upload was cancelled, or server error encountered');
}
}
/**
* Process a delete.
* @param string $uploadDirectory Target directory.
* @params string $name Overwrites the name of the file.
*
*/
public function handleDelete($uploadDirectory, $name=null)
{
if ($this->isInaccessible($uploadDirectory)) {
return array('error' => "Server error. Uploads directory isn't writable" . ((!$this->isWindows()) ? " or executable." : "."));
}
$targetFolder = $uploadDirectory;
$uuid = false;
$method = $_SERVER["REQUEST_METHOD"];
if ($method == "DELETE") {
$url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$tokens = explode('/', $url);
$uuid = $tokens[sizeof($tokens)-1];
} else if ($method == "POST") {
$uuid = $_REQUEST['qquuid'];
} else {
return array("success" => false,
"error" => "Invalid request method! ".$method
);
}
$target =
没有合适的资源?快使用搜索试试~ 我知道了~
fine-uploader php的demo
共43个文件
map:11个
js:8个
gif:7个
需积分: 10 14 下载量 75 浏览量
2017-03-02
16:28:40
上传
评论 1
收藏 1.2MB ZIP 举报
温馨提示
html php js 多文件上传不用插件; 百度一下fine uploader 这是一个可以直接拷贝到php服务器中运行的demo, 一分钟不再死去活来
资源推荐
资源详情
资源评论
收起资源包目录
fine-uploader-demo.zip (43个子文件)
fine-uploader-demo
server
composer.json 207B
endpoint-cors.php 6KB
handler.php 12KB
endpoint.php 3KB
files
fine-uploader
dnd.min.js.map 79KB
dnd.js 46KB
jquery.fine-uploader.min.js 141KB
templates
default.html 3KB
simple-thumbnails.html 4KB
gallery.html 5KB
continue.gif 221B
fine-uploader-gallery.min.css.map 3KB
fine-uploader.js.map 601KB
jquery.fine-uploader.js.map 619KB
trash.gif 159B
fine-uploader.core.min.js 101KB
fine-uploader.min.css.map 2KB
fine-uploader-gallery.min.css 7KB
fine-uploader.js 338KB
LICENSE 1KB
retry.gif 173B
pause.gif 142B
fine-uploader.core.min.js.map 443KB
fine-uploader.min.js.map 587KB
processing.gif 3KB
fine-uploader.core.js.map 453KB
fine-uploader.core.js 251KB
fine-uploader.min.js 138KB
placeholders
waiting-generic.png 6KB
not_available-generic.png 4KB
fine-uploader.css 5KB
fine-uploader-new.min.css 5KB
fine-uploader.min.css 4KB
fine-uploader-new.min.css.map 3KB
jquery.fine-uploader.js 348KB
jquery.fine-uploader.min.js.map 605KB
edit.gif 150B
fine-uploader-gallery.css 11KB
dnd.js.map 82KB
dnd.min.js 18KB
loading.gif 2KB
fine-uploader-new.css 7KB
client.html 5KB
共 43 条
- 1
资源评论
古德慢
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- stm32f103c8t6+hc05+l298n蓝牙小车
- WPF 自定义控件,模仿combobox控件
- 四旋翼双环pid控制matlab版本R2020b源码.zip
- fbbev在自己电脑上转onnx遇到资源问题,试着放在公用机上运行
- 微信小程序源码 V2EX - 创意、技术和分享的社区平台
- 基于Python+OpenFace+MySQL开发人脸识别的课堂考勤系统源码+pyqt5界面+使用说明.zip
- 微信小程序源码 高效任务管理 - 专业级Todo List应用下载
- 深度老龄化社会背景下老年人文娱生活的现状及新路径研究.caj
- 微信小程序源码 TCP/IP长连接实现 - 高效网络通信解决方案
- 基于RSSI测距的多边定位法matlab仿真源码及python源码(95分以上).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功