PHP file upload error

I am trying to upload an image file using php. I use a simple file that downloads code, for example, at www.w3schools.com/php/php_file_upload.asp, however sometimes the php file doesn’t upload images,

Images are not so big. One size is only 130 KB, the download process reaches 48% fine, and then slows down to 72% after a long time and gives me the error "Incomplete request". Is there any way to fix this thanks.

Edit

Code:

$allowedExts = array("jpg", "jpeg", "gif", "png"); $extension = end(explode(".", $_FILES["file"]["name"])); if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 2000000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } 
+4
source share
1 answer

I think you should try first

 $foo = explode('.', $_FILES['file']['name']); $extension = end($foo); move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; 

Then:

  • Enlarge uploaded images
  • Then in your file, where all the content is located, create a folder in which you want to save your photos, the folder should have the name upload
-1
source

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


All Articles