嘿伙计们,我试图让图片上传到指定的目录,所有我得到的输出是'上传文件时出错,请再试一次!'
$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!";
}
有什么想法吗?
答案 0 :(得分:0)
如果您没有收到警告,这是唯一的原因:If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
来自文档的引用。
使用.is_uploaded_file检查上传。