_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:
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.
Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.