Yea yea I know this question has been asked before but I just would like to know how I can modify this code in order to have it upload multiple images into the database, I’ve searched up and down this forum and could not find anything that could help me so if someone has knowledge please help me out?
<?php
$fileName = $_FILES["uploaded_file"]["name"]; // The file name
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is
$fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 for false... and 1 for true
$fileExt = end($kaboom);
if (!$fileTmpLoc) { // if file not chosen
echo "ERROR: Please browse for a file before clicking the upload button."; exit();
}
else if($fileSize > 5242880) {
// if file size is larger than 5 Megabytes
echo "ERROR: Your file was larger than 5 Megabytes in size."; unlink($fileTmpLoc);
// Remove the uploaded file from the PHP temp folder
exit(); } else if (!preg_match("/.(gif|jpg|png|mp4)$/i", $fileName) ) {
// This condition is only if you wish to allow uploading of specific file types
echo "ERROR: Your image was not .gif, .jpg, or .png."; unlink($fileTmpLoc);
// Remove the uploaded file from the PHP temp folder
exit(); } else if ($fileErrorMsg == 1) {
// if file upload error key is equal to 1
echo "ERROR: An error occured while processing the file. Try again."; exit(); }
$moveResult = move_uploaded_file($fileTmpLoc, "uploads/$fileName");
// Check to make sure the move result is true before continuing
if ($moveResult != true) {
echo "ERROR: File not uploaded. Try again."; exit();
}
?>
I feel like I didn’t explain it clear enough but, what I want to do is have just one file field to upload multiple images to the database and have those images still link back to the users id, don’t worry about the linking back part I already know how to do that but having it upload multiple images is the annoying part. what it’s doing is taking the last image that was selected so for example if I selected image1.png, image2.png or image3.png it will only upload image3.png and ignore the first two…does that make sense? and thank you for the links guys will take a look at them. I forgot to include this but this is how they’re being handled: