By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,271 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

upload multiple files if filenames are known in advance

100+
P: 170
Given that I'm trying to automate the process of uploading 20-30 files at a time (and I have to do this regularly), and the filenames are always the same each time (eg. it's always file1.gif, file2.gif, etc), is there some way I can automate this using php? At present, I have a simple form which uploads one at a time, but obviously at this stage I have to keep going back and choosing the file again and again. Is there some way I can tell the script where to get each file without using the browse/upload form as per normal? And then perhaps once it's uploaded the first one, automatically upload the next, and keep going until all the files are done? ftp is not an option. security is not an issue as this is an internal site.

Any suggestions/advice/help would be appreciated. I'm not an expert, but also not a complete newbie.

Thanks
Feb 16 '07 #1
Share this Question
Share on Google+
9 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Put your upload code in a function.
Store your file names in an array.
Loop through that array, calling the upload function at each cyle, until you have processed all array entries.

Ronald :cool:
Feb 17 '07 #2

100+
P: 170
Thanks once again Ronald!
Feb 18 '07 #3

ronverdonk
Expert 2.5K+
P: 4,258
You are welcome.

Ronald :cool:
Feb 18 '07 #4

100+
P: 170
Update...

I asked a friend about doing this and he replied:

"its not possible. Its a security measure in
php, and browsers, that they just cant upload any files without you
filling in the input box."

Is this true? If so, it would mean the method above of storing filenames in an array, putting the upload procedure in a function and then calling the function for each file in the array would not work.

Any clarification? Does my friend know what he's talking about?
Feb 20 '07 #5

100+
P: 170
Well I guess I'll provide clarification. It turns out the automating process cannot be done. In other words, the whole array with filenames, then loop through the array is not possible...for anyone else who wondered...
Feb 21 '07 #6

ronverdonk
Expert 2.5K+
P: 4,258
I am so sorry, but your friend is right!

I was thinking about an FTP upload from an array. And I completely overlooked your statement that you could not use FTP for this.

I am terribly sorry about the confusion I caused you.

Ronald :cool:
Feb 21 '07 #7

100+
P: 170
No problem at all! I'm just glad to have some closure on it. I've ended up achieving the same thing using a zip class, uploading the zipped file (containing all my files), extracting the file using the class and then deleting the zip file. It works well...
Feb 21 '07 #8

ronverdonk
Expert 2.5K+
P: 4,258
I am glad you found a solution to your problem. Wish I had seen your no-FTP before. Come back here any time.

Ronald :cool:
Feb 22 '07 #9

tolkienarda
100+
P: 316
here is a link that i found useful trying to do the same thing you were trying to do
http://www.it-guru.co.uk/showthread.php?t=923

it is a script to uploading multiple files dunno if it can be modified to do what you want.

eric
Feb 22 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.