【发布时间】:2011-06-01 08:56:47
【问题描述】:
大家好,我正在尝试将图像上传到指定目录,我得到的所有输出都是“上传文件时出错,请重试!”
$upload_dir = "blog/wp-content/uploads/products";
if (file_exists($upload_dir) && is_writable($upload_dir)) {
echo "Directory exists and is fine....";
}
else {
echo "Upload directory is not writable, or does not exist.";
}
$target_path = "blog/wp-content/uploads/products/";
$target_path = $target_path . basename( $_FILES['image_file']['name']);
if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['image_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
有什么想法吗?
【问题讨论】:
-
你也应该检查
$_FILES['image_file']['error']中的上传状态(php.net docs)这个错误代码可能表明失败的原因是什么 -
您真的不应该保留原始文件名。想象一下有人上传了一个 php 文件,你的网络服务器会很乐意运行它。
标签: php debugging image-processing error-handling