When I upload an imagen with PHP, I get no errors and the image is 0 bytes on server. Things considered:
- File_uploads is On in phpinfo()
- Upload_max_filesize is 8M in phpinfo()
- Upload_tmp_dir is set and has 777 permisions
- If I run file_exists($_FILES['userfile']['tmp_name']), it returns true
- If i run getimagesize($_FILES['userfile']['tmp_name']), I get an Read Error notice. The image is valid and can be opened with system image viewer
I am using a very simple upload script for testing:
HTML:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
PHP:
<?php
//$uploaddir = '/var/www/html/upload';
$uploaddir = '';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
When I submit the file, I get no errors and the image is created in the destination folder, with the correct name and extension, but as the title says, it is 0 bytes (of course, it can't be oppened).
Thanks for your time.
EDIT Sajad Karuthedath just made me see that $_FILE['file']['size'] value is 0 !! What can be the problem causing files are not being uploaded correctly?
EDIT 2 Uploading txt, pdf, tar files is working properly.. The problem is only with image type files!
$uploaddir = 'upload/';if running your script from the root of your server.error_reporting(E_ALL); ini_set('display_errors', 1);. Also try$uploadfile = $uploaddir ."/" . basename($_FILES['userfile']['name']);but your$uploaddir = '';is empty, so that could be a factor.