I’m having a hard time trying to upload all the images
Here is my php to try & so that
echo 'Upload Diectory: '.$upload_directory;
$tmp = $_FILES['Thumb']['tmp_name']; // Create and ppend a variable to tmp_name
$image = $thumb; // Create and append a variable to tmp_name
require('test_image.php');
echo '<br>Featured Pic: '.$tmp.' => '.$file;
move_uploaded_file($tmp, $file);
}
//upload pictures
if(isset($_FILES['Image']['name'][0])) {
$total = count($_FILES['Image']['name']);
echo '<pre>';print_r($_FILES['Image']);echo '</pre>';
echo '<br>Count of Images: '.$total.', to be uploaded!<br>';
// Loop through each file
for($i = 0; $i < $total; $i++) {
$tmp = $_FILES['Image']['tmp_name'][$i]; // Create and ppend a variable to tmp_name
$image = $_FILES['Image']['name'][$i]; // Create and append a variable to tmp_name
require('test_image.php');
echo '<br>Image '.$i.': '.$tmp.' => '.$file;
move_uploaded_file($tmp, $file);
}
} // do nothing if the first image isn't selected (meaning no image is selected)
the result seems to be only 1 image seems to be there, why not all 3?
When I open up that developer console and take a look at the output I notice that the two images appear in some array
I dont see why in the output section, the whole POST array isn’t visible.
Do you know why that is?
Also when I submit the form to this php code,
So is there a problem with the js whick lets me select multyiple images, that would be my uploiads.js but I think this is what is what im thinking the error must be coming from
Well, I don’t know, which is why I keep asking about the code that handles that. I know you’re dealing with a $_POST array in your PHP, and I can see from your screen shots that it is not receiving the array as you might expect it to. Therefore, the issue must lie in whatever code goes between your <input> and the next stage of the process, which presumably is your uploads.js code. Either it’s not populating the images array in the way you expect it, or it’s not sending all of the array when the form is submitted.
What I’m wondering is, what happens when you hit the “+” button to add another image? Is it duplicating the html input in code? If so, does it change the id parameter, and if it does not change that, does the code that gathers the inputs do so using the id, so will having duplicates cause more trouble than having any html element with a duplicate id?
when i print out the Image
So it looks like your right as the array only holds 1 image and is overwritten whenever a new image is selected.
I thought I was on the right track when I made the name of the image thing in uploads.js to be Image to make each image added to the array, but I gather my logic is flawed.
I’m not that experienced in javascript, but your code there seems to be building up an array called names which contains the filenames as they are added to the form. I can’t see where the actual upload is handled - can you show the code for that part? If you have a look at the <form> tag or the <submit> tag, there may be a link to another js function. In your PHP, have you tried just doing a var_dump($_FILES) or var_dump($_POST) to see what’s there?
Which is only slightly tight as I choose three images, but the FILES{} only has the Image
Im not too experienced in javasript either but im thinking the forms upload button (and also any image choosen there-after is preformed by this part
I thought simply changing the name of the input to an array would ensure there would be an image in [0][1] and [2] of that array (Image[0] would be the first, Imagee[1] would be the second, and Image[2] would be the third)I
The forms method is to a php page so I thought only PHP would handle the data, no? If there is a BETTER WAY TO ACHIEVE THIS RESULT, LET ME KNOW BUT THE ONLY REASON i WANT THIS TO WORK IS SO THAT PEOPLE CAN PREVIEW AN IMAGE BEFORE IT IS UPLOADED.
Is “ADD PROVIDER” the button you click to actually submit the form to the PHP? What is the code for that? I think the code you’ve shown is to add an image to the form, not to actually submit the form.
What was it, before you changed it? If this is an image upload script you’ve got from somewhere, did it support multiple images before?
I think I made a learning mistake as I just was so excited I found a way to preview images before upload I didnt bother to read any docs about its use. I assumed it\ put the files into an array because nothing seemed to happen when an image was selected
I noticed the image was added to the names which is output to the console
But when the form is submitted, there is no mention of the names array, since its not in the POST of FILES arrays do that mean these files (names) is not being attached to the form like I thought?
I think there might be an easier way to simply add a preview-thing to any image before its uploaded
And everything works like I hoped.
I was only selecting one image at a time because I wanted to ensure the upload thing could be used by all (even users who only know how to select only 1 thing at a time & are clueless when it comes to the shift or control ,keys)