Jump to content

Modify code for multiple file uploads


daveyah2002

Recommended Posts

Hi,

 

I have attached a couple of files.

File single.txt contains the code to upload a single selected file to a server with a random name and write the name to an SQL database.

 

I am really just stumbling around in the dark trying to modify the code (in multiple.txt) so it will upload multiple files.

The code in multiple.txt isn't falling over but it still just uploads one file and writes one filename to the database.

 

The photo form has been modified to accept a multiple file selection and the number of selected files is indicated in the browser.

 

input type = "file" name="photo" multiple="multiple" accept="image/*

 

Any pointers as to where I am going wrong would be appreciated.

file single.txt

file multiple.txt

Link to comment
Share on other sites

Overall your code is fine in filemultiple.txt. The issue is to do with line 68 through to line 70.  This is because the code will upload the first file and then it will redirect the user to photos.php after its details have been inserted into the database.

 

You want the code to continue looping over the remaining uploaded files. To prevent this you need to move these three lines so they are not inside the for loop.

So line 68 through to line 71 should read as follows

	} // this closes the for loop. We do want the following lines inside the loop
mysqli_close($db_conx);
header("location: ../photos.php?u=$log_username");
exit();
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.