cdoggg94 Posted May 23, 2012 Share Posted May 23, 2012 I want to use the type of upload below and edit it so that i can upload multiple files at once instead of just one at a time, any suggestions ? <?php mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("my_db") or die(mysql_error()); $picture = $_FILES['image']['tmp_name']; $brand = $_POST['brand']; $year = $_POST['year']; $story = $_POST['story']; $description = $_POST['description']; $pairings = $_POST['pairings']; $lcbo = $_POST['lcbo']; $size = $_POST['size']; $btl = $_POST['btl']; $price = $_POST['price']; $lto = $_POST['lto']; $catagory = $_POST['catagory']; if(!isset($picture)) echo ""; else { $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($_FILES['image']['tmp_name']); $max_width = 250; $max_height = 377; list($width, $height) = $image_size; //echo $width.",".$height; $ratioh = $max_height/$height; $ratiow = $max_width/$width; $ratio = min($ratioh, $ratiow); // New dimensions $mywidth = intval($ratio*$width); $myheight = intval($ratio*$height); if($image_size==FALSE) echo "No image was seleted"; else{ if(!$insert = mysql_query ("INSERT INTO product_tbl VALUES ('','".$image_name."','".$image."','".$myheight."','".$mywidth."','".$lcbo."','".$brand."','".$year."','".$size."','".$btl."','".$price."','".$lto."','".$sweet."','".$acid."','".$oak."','".$body."','".$intensity."','','".$story."','".$description."','".$why."','".$catagory."','".$pairings."')")) echo "Problem Uploading Image."; else{ $lastid = mysql_insert_id(); echo "Product added!<p />".$text."<p /><p /> This is what will appear on your page:<p /> <table border='0'> <tr> <td valign='top'><img src=get_2.php?Product=$lastid height='".$myheight."' width='".$mywidth."' ></td> <td valign='top'> Brand: ".$brand." <p> Company: ".$catagory."</p> <p> Year: ".$year."</p> <p> Story: ".$story."</p> <p> Description: ".$description."</p> <p> Parings: ".$Pairings."</p> <p> LCBO #: ".$lcbo."</p> <p> Size: ".$size."</p> <p> Btl: ".$btl."</p> <p> Price: ".$price."</p> <p> Lto: ".$lto."</p> </td> </tr> </table> "; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 23, 2012 Share Posted May 23, 2012 Use an array name for the form field and loop over the resulting array in your php code. See example #3 in the php documentation - http://www.php.net/manual/en/features.file-upload.post-method.php Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/#findComment-1347926 Share on other sites More sharing options...
cdoggg94 Posted May 23, 2012 Author Share Posted May 23, 2012 this might be a dumb question, but like i get the IDEA of it now, but im not sure how to implement it into my upload. Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/#findComment-1347939 Share on other sites More sharing options...
cdoggg94 Posted May 23, 2012 Author Share Posted May 23, 2012 I have also been trying it in here: <?php set_time_limit(0); require_once("Connections/myConnect.php"); mysql_select_db("my_db"); $preName = $_POST['name']; $preText = $_POST['text']; $preLink = $_POST['links']; foreach ($_FILES["picture"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["picture"]["tmp_name"][$key]; $name = $_FILES["picture"]["name"][$key]; move_uploaded_file($tmp_name, "data/$name"); } } $filetype = $_FILES['pic']['type']; if($filetype == "image/jpeg" or $filetype == "image/pjpeg") { $target_path = "images/".$target_path.basename( $_FILES['pic']['name']); $showname = basename( $_FILES['pic']['name']); if(move_uploaded_file($_FILES['pic']['tmp_name'], $target_path)) { $querystring = "INSERT INTO presentation_tbl(event3_id,event3_pic,event3_title,event3_content,event3_alt) VALUES(NULL,'".$showname."','".$title."','".$story."','".$alttext."')"; $doquery = mysql_query($querystring); echo ""; } else{ echo "There was an error uploading the file, please try again!"; } } ?> this is very obviously wrong... The $filetype to $showname lines are how i handled a single file upload, again i dont know how to adampt the multi file part to it Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/#findComment-1347956 Share on other sites More sharing options...
cdoggg94 Posted May 23, 2012 Author Share Posted May 23, 2012 my form looks like this: <form action="admin_presentation2.php" method="post" enctype="multipart/form-data"> <table border="0"> <tr> <td align="right">Name: </td> <td colspan="2"><input name="name" type="text" /></td> </tr> <tr> <td align="right">Text: </td> <td colspan="2"><input name="text" type="text" /></td> </tr> <tr> <td align="right">Links: </td> <td colspan="2"><input name="links" type="text" /></td> </tr> <tr> <td align="right">Banner: </td> <td colspan="2"><input name="banner" type="file" /></td> <td>(800px X 152px)</td> </tr> <tr> <td align="right">Logo1: </td> <td colspan="2"><input name="logo1" type="file" /></td> </tr> <tr> <td align="right">Logo2: </td> <td colspan="2"><input name="logo2" type="file" /></td> </tr> <tr> <td align="right">Logo3: </td> <td colspan="2"><input name="logo3" type="file" /></td> </tr> <tr> <td><input name="id" type="hidden" value="" /></td> <td colspan="2"><input name="submit" type="submit" value="Add!" /></td> </tr> </table> </form> if that means anything to anyone Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/#findComment-1347958 Share on other sites More sharing options...
cdoggg94 Posted May 23, 2012 Author Share Posted May 23, 2012 sorry that was the old form... this is the new version: <form action="admin_presentation2.php" method="post" enctype="multipart/form-data"> <table border="0"> <tr> <td align="right">Name: </td> <td colspan="2"><input name="name" type="text" /></td> </tr> <tr> <td align="right">Text: </td> <td colspan="2"><input name="text" type="text" /></td> </tr> <tr> <td align="right">Links: </td> <td colspan="2"><input name="links" type="text" /></td> </tr> <tr> <td align="right">Banner: </td> <td colspan="2"><input name="picture[]" type="file" /></td> <td>(800px X 152px)</td> </tr> <tr> <td align="right">Logo1: </td> <td colspan="2"><input name="picture[]" type="file" /></td> </tr> <tr> <td align="right">Logo2: </td> <td colspan="2"><input name="picture[]" type="file" /></td> </tr> <tr> <td align="right">Logo3: </td> <td colspan="2"><input name="picture[]" type="file" /></td> </tr> <tr> <td><input name="id" type="hidden" value="" /></td> <td colspan="2"><input name="submit" type="button" value="Add!" /></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/#findComment-1347960 Share on other sites More sharing options...
DavidAM Posted May 23, 2012 Share Posted May 23, 2012 Your "$filetype and $showname" stuff should be inside the loop, too. Basically, inside the loop, you process ONE file, as if it were a single-file upload --- well, the FILES array is slightly different. Quote Link to comment https://forums.phpfreaks.com/topic/262989-multiple-file-upload/#findComment-1347979 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.