raven2009 Posted April 7, 2009 Share Posted April 7, 2009 hi all i was wondering how can you insert a mulit upload form, from an existing upload form? i want to be able to add 5 things in 1 go Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/ Share on other sites More sharing options...
JasonLewis Posted April 7, 2009 Share Posted April 7, 2009 Not possible with just PHP, at least, as far as I know. JavaScript and Flash are capable of doing this though. Frameworks like jQuery can help you out. Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803390 Share on other sites More sharing options...
jerry89 Posted April 7, 2009 Share Posted April 7, 2009 Hi, I got one script its for 3 at the moment, but I belive you can make it for more. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803394 Share on other sites More sharing options...
raven2009 Posted April 7, 2009 Author Share Posted April 7, 2009 Hi, I got one script its for 3 at the moment, but I belive you can make it for more. Thank you so much for your help ill take a look at this see if i can make it work ill let you know how i go Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803399 Share on other sites More sharing options...
wrathican Posted April 7, 2009 Share Posted April 7, 2009 the best you can do i have x amount of file input boxes and select an file for each. name them all something like 'file[]' ensuring you have the '[]' in the name. this will submit the x amount of files as an array. simply loop through them on the processing page. $x = $_FILES['file']; // this is an array containing all of the files selected for($i = 0; $i < count($x); $i++){ echo $x[$i]['name']; } Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803510 Share on other sites More sharing options...
raven2009 Posted April 7, 2009 Author Share Posted April 7, 2009 the best you can do i have x amount of file input boxes and select an file for each. name them all something like 'file[]' ensuring you have the '[]' in the name. this will submit the x amount of files as an array. simply loop through them on the processing page. $x = $_FILES['file']; // this is an array containing all of the files selected for($i = 0; $i < count($x); $i++){ echo $x[$i]['name']; } ok thanks for you reply how would i implement that in this code in the tables part or the 1st part? table? <table width="409" border="1" align="center" bordercolor="#C9D4E3" bgcolor="#C9D4E3"> <form action="" enctype="multipart/form-data" method="post"> <tr> <td width="189" bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Image </strong></div></td> <td width="344" bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> <label> <input name="uploadedfile" type="file" /> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Name </strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <label> <input name="retailername" type="text" id="retailername"> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Category </strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <select name="category"> <?php $listCategories="select * from categories"; $listCats=mysql_query($listCategories); while($row=mysql_fetch_array($listCats)) { ?> <option value="<?php echo $row['id']; ?>"><?php echo $row['category']; ?></option> <? } ?></select> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailer Keywords</strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <label> <input name="keywords" type="text" id="keywords"> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center" class="style1"> <p><strong>Cashback Offered</strong></p> </div> <label></label></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p> <label> <input type="radio" name="cashback" value="£"> £</label> <br> <label> <input type="radio" name="cashback" value="%"> %</label> <br> <label></label> </p> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p> </p> <p><strong>Cash Back Amount </strong></p> </div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p> </p> <p> <label> <input name="cashback_amount" type="text" id="cashback_amount"> </label> </p> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p><strong>Retailer Short Info</strong><strong> </strong></p> </div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <label> <textarea name="shortinfo" id="shortinfo"></textarea> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p><strong>Terms of sale</strong></p> </div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <label> <textarea name="terms" id="terms"></textarea> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Retailers Full Info </strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <label> <textarea name="fullinfo" id="fullinfo"></textarea> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p><strong>Retailers Link</strong></p> </div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <label> <textarea name="link" id="link"></textarea> </label> </div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"></div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"></div></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"><strong>Other Info </strong></div></td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><label> <div align="center"> <textarea name="other" id="other"></textarea> </div> </label></td> </tr> <tr> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"> </td> <td bordercolor="#C9D4E3" bgcolor="#C9D4E3"><div align="center"> <p> </p> <p> <input name="addRetailer" value="addRetailer" type="hidden"> <input name="image" type="image" src="../images/site/submit_button_green.gif" alt="Submit" width="124" height="24" border="0"> </p> </div></td> </tr> </table> (function) <?php require_once('../config.php'); if(isset($_POST['addRetailer']) && $_POST['addRetailer']=='addRetailer') { $target_path = "uploads/"; $img_path=time()."_".basename( $_FILES['uploadedfile']['name']); $target_path = $target_path .$img_path ; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { // echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $retailername=$_POST['retailername']; $keywords=$_POST['keywords']; $cashback=$_POST['cashback']; $cashback_amount=$_POST['cashback_amount']; $shortinfo=$_POST['shortinfo']; $terms=$_POST['terms']; $fullinfo=$_POST['fullinfo']; $link=$_POST['link']; $other=$_POST['other']; $category=$_POST['category']; $addRetailer="insert into retailers(id,retailername,keywords,cashback,cashback_amount,shortinfo,terms,fullinfo,link,other,image,category) values('','$retailername','$keywords','$cashback','$cashback_amount','$shortinfo','$terms','$fullinfo','$link','$other','$img_path','$category')"; //echo $register; $addRetailer=mysql_query($addRetailer); if($addRetailer) { ?> <script language="javascript1.1"> alert('Store added successfully!'); </script> <? } else { ?> <script language="javascript1.1"> alert('Store not added! please try again.'); </script> <? } } ?> Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803544 Share on other sites More sharing options...
raven2009 Posted April 7, 2009 Author Share Posted April 7, 2009 the best you can do i have x amount of file input boxes and select an file for each. name them all something like 'file[]' ensuring you have the '[]' in the name. this will submit the x amount of files as an array. simply loop through them on the processing page. $x = $_FILES['file']; // this is an array containing all of the files selected for($i = 0; $i < count($x); $i++){ echo $x[$i]['name']; } ??? Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803675 Share on other sites More sharing options...
charleshill Posted April 7, 2009 Share Posted April 7, 2009 Ahem.... You can do multiple file uploads like this: <form action="" method="post" enctype="multipart/form-data"> <input type="file" name="upload_files[]" value="" /> <input type="file" name="upload_files[]" value="" /> <input type="file" name="upload_files[]" value="" /> <input type="submit" value="Upload" /> </form> Then the PHP can get complicated, because there's lots of checks you'll want to do for file uploads. I do the following just to get a more easy-to-work with array from $_FILES $files = array(); foreach ($_FILES[$key]['tmp_name'] as $n => $dummy) if (!empty($_FILES[$key]['tmp_name'][$n])) $files[$n] = array( 'tmp_name' => $_FILES[$key]['tmp_name'][$n], 'name' => $_FILES[$key]['name'][$n], 'size' => $_FILES[$key]['size'][$n], 'error' => $_FILES[$key]['error'][$n], 'type' => $_FILES[$key]['type'][$n], ); $key would be 'upload_files' in this example, because the name of the upload field is 'upload_files' I then do foreach ($files as $file) to process each file individually making checks like file size, file extension, etc etc Link to comment https://forums.phpfreaks.com/topic/152976-multi-upload/#findComment-803702 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.