phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


Upload File : Upload Multi File (Part 2)

Tag: upload   Category: PHP Basic
post: 06 Dec 2007 read: 1,445


After build single upload file form, we will build multi files uploaded. It is simple. We just use array in our form.

forms.php


 <html>
 <head>
 <title>Form Upload Files</title>
 </head>
 <body>
 <form method="post" enctype="multipart/form-data" action="uploads.php">
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="file" name="ufile[]" /><br />
 <input type="submit" name="submit"
 value="Submit" />
 </form>
 </body>
 </html>

Then, following line codes for uploads.php:


 <?
 $uploaddir  = "C:\\AppServ\\www\\test\\upload\\";
 
 for($i=0;$i<10;$i++){
   	if($_FILES['ufile']['name'][$i]){
     		$uploadfile = $uploaddir. $_FILES['ufile']['name'][$i]; 	
     		if(move_uploaded_file($_FILES['ufile']['tmp_name'][$i], $uploadfile)){
       			echo "File #".($i+1).": upload success <br />";
     		}else{
       			echo "File #".($i+1).": fail <br />";
     		}
   	}
 }
 ?>


Series this article:
Upload : Simple Upload a File (Part 1)
Upload File : Upload Multi File (Part 2)

| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Joomla: Fast Road to Understand Component Programming
Chart: How to Build Cool Animation Real Time Chart
Email: Send Attachement Mail
SMS : Sending SMS with PHP and ActiveXperts (Part 1)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


624
posting