PDA

View Full Version : Multiple file upload using PHP


choowner
04-30-2007, 06:24 PM
Hey PHP folks,

Can anyone please tell me if multiple file uploading can be done in PHP? For example lf a person has 30 files and wants to upload all at once without having him to select each file and then upload. Working example in Flash: http://www.element-it.com/Examples/MultiPowUpload/SimpleUpload.html but I want to do it in PHP.

P.S. Is uploading a whole folder also possible in PHP?

Thanks!

devinemke
04-30-2007, 06:47 PM
just use mutiple file input tags

<form action="" method="POST" enctype="multipart/form-data">
1. <input type="file" name="1"><br>
2. <input type="file" name="2"><br>
3. <input type="file" name="3"><br>
<input type="submit" name="submit" value="submit">
</form>

<?php
echo '<pre>'; print_r($_FILES); echo '</pre>';
?>

choowner
04-30-2007, 06:49 PM
hi Devinemke,

Thanks for the prompt reply. Actually, thats the thing, I DO NOT want to use multiple form elements. I want something like http://www.element-it.com/Examples/MultiPowUpload/SimpleUpload.html , when you click on Browse, you should be able to select all the files you want to upload at once.

All the help is greatly appreciated.

rafiki
05-01-2007, 01:00 PM
that uses flash, maybe try asking around in the flash forum

JohnDubya
05-01-2007, 08:18 PM
Actually, the best thing to do would be to put the files into an array. Then you can count() how many key/value pairs there are and only upload that many files. You would need to make the "name" attribute the same on all the file fields and also put [] after each name. For example:

<form action="" method="POST" enctype="multipart/form-data">
1. <input type="file" name="user_files[]"><br>
2. <input type="file" name="user_files[]"><br>
3. <input type="file" name="user_files[]"><br>
<input type="submit" name="submit" value="submit">
</form>

Read more about multiple file uploads:
http://www.php.net/manual/en/features.file-upload.multiple.php

And next time, Google for what you're wanting to know. I Googled "upload multiple files php" and got tons of good results.

aedrin
05-01-2007, 09:49 PM
I think he wants the HTML interface to only have 1 input, not on the PHP side.

I don't think it is possible with standard HTM elements. I'm sure a lot of websites would already be using it if it were.

JohnDubya
05-01-2007, 10:01 PM
choowner, check out this link. It looks promising:

http://the-stickman.com/web-development/javascript/upload-multiple-files-with-a-single-file-element/