大家好,我正在尝试将图像上传到指定目录,并且所有输出结果都是“上传文件时出错,请重试!”
$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!";
}
有任何想法吗?
最佳答案
如果未收到警告,则这是唯一的原因:If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
文档中的引号。
使用.is_uploaded_file检查上传。
关于php - 上载图片错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6198607/