Unspecified error with a file upload loop

Web Technologies Web Development 3 years ago

1.89K 1 0 0 0

_x000D_ _x000D_ I'm using a form and a loop to upload multiple image files directly to the file server, but I'm getting a false result with the move_uploaded_file function. Upload Form:

Select the files you would like to upload.

The files will be uploaded to a folder named '".$_SESSION['filename']."'.

Multiple file uploading loop (uploadform.php: if (isset($_POST["submit"])){ foreach ($_FILES['fileToUpload']['name'] as $i => $name) { $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"][$i]); $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); if (strlen($_FILES['fileToUpload']['name'][$i]) > 1) { if (move_uploaded_file($_FILES["fileToUpload"]["name"][$i], $target_file)) { echo "The file'". basename($_FILES["fileToUpload"]["name"][$i]). "' has been uploaded to the server."; } else { echo "
*** ERROR ***
"; echo "Current File basename: ".basename($_FILES["fileToUpload"]["name"][$i])."
"; echo "Current File non-basename: ".$_FILES["fileToUpload"]["name"][$i]."
"; echo "Current File Path: ".$target_file."
"; echo "Image file type: ".$imageFileType."
"; } $count++; } } } When uploading one or multiple files with the form, it goes to the else statement echoing the "ERROR" string. The Apache Error Log comes up blank, so I have no clue what's wrong with the code. I tried echoing the variables used in the loop ($_FILES["fileToUpload"]["name"][$i], $target_file and $imageFileType) but these seem to be fine.

User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 3 years ago
_x000D_ I would put entire foreach loop in try-catch block and see what, if any Exception occurs: try{ // your foreach loop here: } catch(\Exception $e) { echo $e->getMessage(); }
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum


Q

Unity hosting a custom piece of code on own website [on hold]

_x000D_ _x000D_ I was wondering how would you be able to host an "API" on your own website that you...
Q

I am needing advice on a web bot [on hold]

_x000D_ _x000D_ I want to code a bot that has a GUI or CLI doesn't really matter yet but a GUI would...
Q

date and time picker, that can take a max and min absolute time, compatible with react [on hold]

_x000D_ _x000D_ I have an issue with scheduling things in a web platform (react.js), and need a date...

Important Web Technologies Links