I'm trying to upload a file using PHP! I've tried uploading PNG,JPG,PDF,TXT files, these uploads only works when the file size is around 20kb.
When I try to upload files where its size is around 150KB, it prints $_FILE error = 3
and the file name lets say '1234.png' where the tmp_name is empty and the image itself as well! here's my code
ini_set('display_errors',1);
error_reporting(-1);
$imageTmp = addslashes($_FILES['image']['tmp_name']);
//$imageTmp = $_FILES['image']['tmp_name'];
$imageOldName = addslashes($_FILES['image']['name']);
$imageData = file_get_contents($imageTmp);
//$imageData = base64_encode($imageTmp);
echo 'image temp name: '. $imageTmp .' ';
echo 'error: '. $_FILES['image']['error']. ' ';
echo 'image name: '. $imageOldName. ' ';
echo 'image data: '. $imageData. ' ';
echo 'image type:'. $_FILES['image']['type'];
echo "<pre>";
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";
$inipath = php_ini_loaded_file();
if ($inipath) {
echo 'Loaded php.ini: ' . $inipath;
} else {
echo 'A php.ini file is not loaded';
}
I've tried multiple solutions such as changing the values of post_max_size = 200M
and upload_max_filesize = 200M
instead of 32M
Here's is the result of trying to upload txt file 4KB:
image temp name: /Applications/MAMP/tmp/php/phpOc7d6a error: 0
image Name: test.txt image data: hello image type:text/plain
POST:Array
(
[submit] => Record Test
)
FILES:Array
(
[image] => Array
(
[name] => test.txt
[type] => text/plain
[tmp_name] => /Applications/MAMP/tmp/php/phpOc7d6a
[error] => 0
[size] => 405
)
)
Loaded php.ini: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
the result of uploading PNG file 127KB:
Warning: file_get_contents(): Filename cannot be empty in path/test1.php on line 10 image temp name: error: 3 image name: IMG_8807.JPG image data: image type:
POST:Array
(
)
FILES:Array
(
[image] => Array
(
[name] => IMG_8807.JPG
[type] =>
[tmp_name] =>
[error] => 3
[size] => 0
)
)
Loaded php.ini: /Applications/MAMP/bin/php/php5.6.10/conf/php.ini
BTW, after a failed upload, the server crashes and display 502 Gateway and I have to restart the Apache!
upload_max_filesize
as200M
when you callphpinfo()
. - Anish Silwal