Unable to upload file due to size

I am trying to upload a file using PHP! I tried to download PNG, JPG, PDF, TXT files, these downloads only work when the file size is about 20 KB. When I try to download files that are about 150 KB in size, it prints $_FILE error = 3 , and the file name allows me to say "1234.png", where tmp_name is empty and the image itself! here is 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 tried several solutions, such as changing the values โ€‹โ€‹of post_max_size = 200M and upload_max_filesize = 200M instead of 32M

Here is the result of trying to download a txt 4KB file:

 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 

127KB PNG file download result:

Warning: file_get_contents (): file name cannot be empty in path / test1.php on line 10 image template 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 

By the way, after a failed download, the server crashes and displays the 502 gateway, and I need to restart Apache!

+5
source share
1 answer

As the php documentation says:

 UPLOAD_ERR_PARTIAL is given when the mime boundary is not found after the file data. A possibly cause for this is that the upload was cancelled by the user (pressed ESC, etc). 

Maybe:

  • Permissions are invalid

  • Not enough free space on the server.

  • Download from iOS.

  • This error may occur when loading a folder due to browser restrictions. It happens on Mac OS X.

Here are some things you could try. Hope this helps.

0
source

Source: https://habr.com/ru/post/1238392/


All Articles