开发者

Uploading image error

Hey folks, im trying to get an image to upload to the specified directory and all im getting as an output is 'There was an error uploading the file, please try again!'

$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['i开发者_如何转开发mage_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!";

}

Any ideas?


If you do not receive an warning, this is the only reason: If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE. an quote from the documentation.

Check the upload using .is_uploaded_file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜