Real Ajax Uploader Error: Cannot write on file
Real Ajax Uploader Error: Cannot write on file
我正在构建一个需要能够上传大型 .wav 文件的站点。我认为上传这些文件的最佳方式是通过 jQuery 插件,该插件可以将数据分块到服务器。我选择 Real Ajax Uploader 来执行此操作。
我将以下内容放在一起,它适用于较小的文件:
$('.demo').ajaxupload({
url : '/upload.php',
remotePath: '/remote/path/',
maxFiles: 1,
maxFileSize: '250M',
});
当我有一个涉及 "chunking" 的较大文件时,就会出现问题。由于某种原因,脚本一直给我这个错误:
Cannot write on file.
我已经追踪到 upload.php 文件中的这个位置:
...
//start of the file upload, first chunk
if ($currByte == 0) {
$tempFile = tempnam($this->tempPath, 'axupload');
$this->tempFileName = basename($tempFile);
}
// some rare times (on very very fast connection), file_put_contents will be unable to write on the file,
// so we try until it writes for a max of 5 times
$try = 5;
while (file_put_contents($tempFile, $fileChunk, FILE_APPEND) === false && $try > 0) {
usleep(50);
$try--;
}
//if the above fails then user cannot write file due to permission or other problems
if (!$try) {
$this->message(-1, 'Cannot write on file.');
}
...
我认为这意味着 $tempFile
不可写,所以我添加了这一点:
...
//start of the file upload, first chunk
if ($currByte == 0) {
$tempFile = tempnam($this->tempPath, 'axupload');
$this->tempFileName = basename($tempFile);
}
chmod($tempFile, 0755);
...
我又试了一遍,还是有问题,所以我把/tmp的权限改成了755,心想也许是这样。再一次,什么都没有。
我可以尝试只更改 /tmp 目录的位置并拥有一个更可写的环境,但如果有更简单的解决方案,我宁愿采用它。
谢谢。
首先在目录下上传一个小文件,检查是否上传成功。如果成功,则搜索 php.ini
设置文件并检查以下内容:
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300
更新以上所有设置以满足您的要求,然后重新启动服务器,然后重试。
我正在构建一个需要能够上传大型 .wav 文件的站点。我认为上传这些文件的最佳方式是通过 jQuery 插件,该插件可以将数据分块到服务器。我选择 Real Ajax Uploader 来执行此操作。
我将以下内容放在一起,它适用于较小的文件:
$('.demo').ajaxupload({
url : '/upload.php',
remotePath: '/remote/path/',
maxFiles: 1,
maxFileSize: '250M',
});
当我有一个涉及 "chunking" 的较大文件时,就会出现问题。由于某种原因,脚本一直给我这个错误:
Cannot write on file.
我已经追踪到 upload.php 文件中的这个位置:
...
//start of the file upload, first chunk
if ($currByte == 0) {
$tempFile = tempnam($this->tempPath, 'axupload');
$this->tempFileName = basename($tempFile);
}
// some rare times (on very very fast connection), file_put_contents will be unable to write on the file,
// so we try until it writes for a max of 5 times
$try = 5;
while (file_put_contents($tempFile, $fileChunk, FILE_APPEND) === false && $try > 0) {
usleep(50);
$try--;
}
//if the above fails then user cannot write file due to permission or other problems
if (!$try) {
$this->message(-1, 'Cannot write on file.');
}
...
我认为这意味着 $tempFile
不可写,所以我添加了这一点:
...
//start of the file upload, first chunk
if ($currByte == 0) {
$tempFile = tempnam($this->tempPath, 'axupload');
$this->tempFileName = basename($tempFile);
}
chmod($tempFile, 0755);
...
我又试了一遍,还是有问题,所以我把/tmp的权限改成了755,心想也许是这样。再一次,什么都没有。
我可以尝试只更改 /tmp 目录的位置并拥有一个更可写的环境,但如果有更简单的解决方案,我宁愿采用它。
谢谢。
首先在目录下上传一个小文件,检查是否上传成功。如果成功,则搜索 php.ini
设置文件并检查以下内容:
php_value upload_max_filesize 10M
php_value post_max_size 10M
php_value max_input_time 300
php_value max_execution_time 300
更新以上所有设置以满足您的要求,然后重新启动服务器,然后重试。