views:

219

answers:

2

Hi I was wondering what the best way to send 6 'file' inputs to a php page would be... and how to process them, i used this website to understand uploading one file

PHP Tutorial - File Uplaod

Also, i want to name each of the 6 images with a time stamp for example below...

00000000
00000001
00000002
00000003
00000004
00000005

Basically i just want to +1 to the time stamp, as well i will be uploading the 6 files at once.. so likely the time-stamps will be the same...

This file input will be implemented into a database.. i am planning on storing the image file name in the database then linking to that file in the uploads folder :)

Could anyone link me to a great tutorial on multiple file uploads, or give me some sample code :D

Thanks in advanced!

+1  A: 

Multiple file uploads work the same way as any single file uploads, which work the same way as any other form component. You simply need to specify an <input type='file' name='whatever'> for each file you want to have uploaded.

Regarding the naming bit, just set the name as you would any other form component:

<input type="file" name="000">
<input type="file" name="001">
...
<input type="file" name="005">

You can then access it using the $_FILES superglobal array.

While we're on the subject, this page provides a very good, detailed overview of how to manage file uploads via HTML forms.

eykanal
HiThanks!Although, i kind of understood that - but your answer isn't really a answering what i am saying.... i want to know how to interpret those 6 posted inputs - then name them with a timestamp +1 from the date() function in php... i am looking more for the PHP than the html...
tarnfeld
Well, the `date()` function in php is really well documented on the php website (http://www.php.net/date). All you would do to name them is:<pre>$name = date(whatever you choose, likely 'YmdHi');$n = (1,2,3,4,5);$filename = array();for($n as $suffix){ $filename[] = $date.$suffix;}</pre>There you go; an array with your file names in them.
eykanal
+1  A: 

I'm pretty sure you can grab the name using the post variable. On the tutorial you linked to, try using $_POST['uploadedfile'] to get the name of the file.

But here is an example of how I handle file uploads where "pageImage" is the name of the file upload field and $filePath is the file upload destination:

if(is_uploaded_file($_FILES[pageImage]['tmp_name'])){
 $filename=time().".jpg";
 move_uploaded_file($_FILES[pageImage]['tmp_name'],$filePath.$filename);
 chmod($filePath.$filename,0775);
}

hope this makes sense.

Dylan