Hello people I want to upload multiple files using php. What I want is when user click on more upload then it should show more file field browser box so that I can select more files. Please help me regarding this.
Create file - multiple_upload.php [COLOR=#666666][FONT=Verdana]<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<form action="multiple_upload_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<td><strong>multiple Files Upload </strong></td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<td>Select file [/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<td>Select file[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<td>Select file[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<input name="ufile[]" type="file" id="ufile[]" size="50" /></td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]<td align="center"><input type="submit" name="Submit" value="Upload" /></td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</table>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</td>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</form>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</tr>[/FONT][/COLOR] [COLOR=#666666][FONT=Verdana]</table>[/FONT][/COLOR] Code (markup): Create file : multiple_upload_ac.php [COLOR=#0000FF][FONT=Verdana]<?php[/FONT][/COLOR][COLOR=#0000FF][FONT=Verdana][COLOR=#009900]//set where you want to store files //in this example we keep file in folder upload //$HTTP_POST_FILES['ufile']['name']; = upload file name //for example upload file name cartoon.gif . $path will be upload/cartoon.gif[/COLOR] $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana][COLOR=#009900]//copy file to where you want to store file[/COLOR] copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); [/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana][COLOR=#009900]//$HTTP_POST_FILES['ufile']['name'] = file name //$HTTP_POST_FILES['ufile']['size'] = file size //$HTTP_POST_FILES['ufile']['type'] = type of file[/COLOR] echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; echo "<img src=\"$path1\" width=\"150\" height=\"150\">"; echo "<P>";[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; echo "<img src=\"$path2\" width=\"150\" height=\"150\">"; echo "<P>";[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; echo "<img src=\"$path3\" width=\"150\" height=\"150\">";[/FONT][/COLOR] [COLOR=#009900][FONT=Verdana]///////////////////////////////////////////////////////[/FONT][/COLOR] [COLOR=#009900][FONT=Verdana]// Use this code to display the error or success.[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]$filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2];[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]if($filesize1 && $filesize2 && $filesize3 != 0) { echo "We have recieved your files"; }[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]else { echo "ERROR....."; }[/FONT][/COLOR] [COLOR=#009900][FONT=Verdana]//////////////////////////////////////////////[/FONT][/COLOR] [COLOR=#009900][FONT=Verdana]// What files that have a problem? (if found)[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]if($filesize1==0) { echo "There're something error in your first file"; echo "<BR />"; }[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]if($filesize2==0) { echo "There're something error in your second file"; echo "<BR />"; }[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]if($filesize3==0) { echo "There're something error in your third file"; echo "<BR />"; }[/FONT][/COLOR] [COLOR=#0000FF][FONT=Verdana]?>[/FONT][/COLOR] Code (markup): P.S Remember to make a folder called "uploads" and CHMOD to 777
Nice effort... but could we do same thing in ajax without refreshing page... can u Plz give me details about that
you can use ajax to submit the form. see this example http://www.simonerodriguez.com/ajax-form-submit-example/