why are images returning filesize = 0 when being uploaded?
I have a php form that uploads files, and all files work good the limit size is set at 7340032 bytes (7Mbs) and it wo开发者_开发技巧rks ok, however when I try to upload an image larger than 500kbs when I echo the values of the first if:
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0){
it says the image size is 0 everytime, why would this happen? the php.ini values of post_max_size is 15M and of upload_max_filesize is 10M.
Checking if the uploaded file's size is non-zero is not the proper way to check if an upload succeeded. There's the ['error']
parameter in there for that. An incomplete upload would still have a non-zero size, but should not be processed. A better way to check is:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_FILES['userfile']['error'] !== UPLOAD_ERR_OK) {
die("File upload error: {$_FILES['userfile']['error']}");
}
... process file here ...
}
The error code constants are defined here.
精彩评论