我没有收到任何错误,但我没有复制文件:
$upload_folder = "uploads/";
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
$prefix = date("YmdHis");
$path_of_uploaded_file = "$upload_folder$prefix-$name_of_uploaded_file";
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
if(is_uploaded_file($tmp_path))
{
if(!copy($tmp_path,$path_of_uploaded_file))
{
$errors .= '\n error while copying the uploaded file';
}
}
echo $path_of_uploaded_file;
echo $name_of_uploaded_file;
echo $errors;
Run Code Online (Sandbox Code Playgroud)
这在Windows开发环境中运行良好,但部署到Linux Web服务器正在执行此操作.我们最初收到了复制错误,然后我们向uploads目录添加了权限.现在我们一无所获.
我也尝试使用move_uploaded_file,没有错误,但在uploads目录中没有生成的文件.
如果is_uploaded_file返回true,也许可以添加一个检查.
if(is_uploaded_file($tmp_path))
{
if(!copy($tmp_path,$path_of_uploaded_file))
{
$errors .= '\n error while copying the uploaded file';
}
} else {
$errors .= '\n error while uploading file'; // maybe upload_max_filesize exceeded
// try to get the specific error
switch($_FILES['uploaded_file']['error']){
case 0: //no error; possible file attack!
echo "There was a problem with your upload.";
break;
case 1: //uploaded file exceeds the upload_max_filesize directive in php.ini
echo "The file you are trying to upload is too big.";
break;
case 2: //uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the html form
echo "The file you are trying to upload is too big.";
break;
case 3: //uploaded file was only partially uploaded
echo "The file you are trying upload was only partially uploaded.";
break;
case 4: //no file was uploaded
echo "You must select an image for upload.";
break;
default: //a default error, just in case! :)
echo "There was a problem with your upload.";
break;
}
Run Code Online (Sandbox Code Playgroud)
也许你的upload_max_filesize超出了,或者有另一个不允许上传的服务器设置.
有关可能出现的问题的更多信息,请参阅php dokumentation.
| 归档时间: |
|
| 查看次数: |
4084 次 |
| 最近记录: |