我正在尝试将“大”文件上传到我的应用程序.用户必须能够上传小于200MB的视频文件,但似乎服务器在4MB或30秒后丢弃连接并且上载失败.
我已经在php.inifile中设置了所有参数,如下所示:
max_input_time = 320
max_execution_time = 320
max_file_uploads = 20
memory_limit = 512M
post_max_size = 201M
upload_max_filesize = 200M
当我上传2MB @ 1Mbps / s的文件时,一切正常(我不知道是否与文件大小或传输时间有关)
可以通过php_info访问live php_info()文件
虽然这里是DropZone.js conf:
$("#dZUpload").dropzone({
url: "/ajax/admin/admin.acceptVideo.php",
maxFilesize: 209715200,
acceptedFiles: "video/*",
addRemoveLinks: true,
dataType: "HTML",
data: { id: '' },
success: function (file, response, data) {
var imgName = response;
file.previewElement.classList.add("dz-success");
$('#form_video').val(imgName);
},
error: function (file, response) {
file.previewElement.classList.add("dz-error");
}
});
Dropzone.autoDiscover = false;
Dropzone.prototype.defaultOptions.dictRemoveFile = "Rimuovi file";
Dropzone.prototype.defaultOptions.dictCancelUpload = "Annulla";
以下是处理上传的PHP脚本:
require_once '../db.config.php';
header('Content-Type: text/plain; charset=utf-8');
ini_set('upload_max_filesize', '200M');
ini_set('post_max_size', '201M');
ini_set('max_input_time', 320);
ini_set('memory_limit', '256M');
try {
if (
!isset($_FILES['file']['error']) ||
is_array($_FILES['file']['error'])
) {
throw new RuntimeException('Invalid parameters.');
}
switch ($_FILES['file']['error']) {
case UPLOAD_ERR_OK:
break;
case UPLOAD_ERR_NO_FILE:
throw new RuntimeException('No file sent.');
break;
case UPLOAD_ERR_INI_SIZE:
break;
case UPLOAD_ERR_FORM_SIZE:
throw new RuntimeException('Exceeded filesize limit.');
break;
default:
throw new RuntimeException('Unknown errors.');
break;
}
// check filesize.
if ($_FILES['file']['size'] > 209715200) {
throw new RuntimeException('Exceeded filesize limit.');
}
// Check MIME Type.
$finfo = new finfo(FILEINFO_MIME_TYPE);
if (false === $ext = array_search(
$finfo->file($_FILES['file']['tmp_name']),
array(
'mp4' => 'video/mp4',
'mov' => 'video/mov',
'avi' => 'video/avi',
),
true
)) {
throw new RuntimeException('Invalid file format.');
}
// name uniquely.
$fileName = sha1_file($_FILES['file']['tmp_name']);
if (!move_uploaded_file($_FILES['file']['tmp_name'], sprintf('/var/www/html/beta.vedocompro.it/web/webtemp/%s.%s', $fileName, $ext ))) {
throw new RuntimeException('Failed to move uploaded file.');
}
try {
$PDO = new PDO('mysql:host=' . $DB_HOST . ';dbname=' . $DB_NAME,$DB_USER,$DB_PASS);
$insert = $PDO->prepare("INSERT INTO `videos` (`id`, `aid`, `accepted`, `uid`, `dir`) VALUES (NULL, '0', '0', '0', $fileName);");
$insert->execute();
echo $fileName;
} catch(PDOException $exception) {
echo $exception;
}
} catch (RuntimeException $e) {
echo $e->getMessage();
}
所以一切似乎都没问题,但服务器在出错之后断开了连接(我认为与PDOquery无关,导致2MB的较小文件将起作用).
你能帮忙找出问题所在吗?
编辑做了一些测试我发现脚本在执行30秒时完全丢失,我试图添加set_time_limit(0);在脚本的顶部,但没有再改变