plugnz Posted May 16, 2010 Share Posted May 16, 2010 Hi there, I am building a site where the owner needs to upload a lot of images at once. Does anyone know if it's possible to upload more than 1 image at once or even a folder full of images using the input type "file" tags? or will i need to save them as a zip first and then get the php to unzip them? if so then how do I do this? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/ Share on other sites More sharing options...
JAY6390 Posted May 16, 2010 Share Posted May 16, 2010 zipping them would make more sense to be honest. You could make a java applet to do it like facebook does but unless you know how to I would recommend the zipping method Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059088 Share on other sites More sharing options...
plugnz Posted May 16, 2010 Author Share Posted May 16, 2010 Ta Jay6390, Have taken that advice on board. Will come back to that one. However as the client is not too keen on the zip method I'd like to at least try the multi-images. I have modified my upload script to allow up to 12 files to be selected: see below: echo "<table >"; echo "<tbody>"; echo "<tr>"; echo "<td valign='top' colspan='4'>"; echo "<h2>Please select an image or images to upload</h2>\n"; $max_no_img = 12 ; for($i=1; $i<=$max_no_img; $i++){ echo ' <input name="image_filename" type="file" size="67" id="image_filename" value="' . $imagefilename . "\">"; } echo "<br></td>"; echo "</tr>"; echo " <tr>"; echo " <td valign='top' colspan= '3'>"; echo ' <input type="submit" class="submit" name="action" ' . "value=\"Upload Image\">\n"; echo "</td>"; echo "</tr>"; echo "</tbody>"; echo "</table>"; now I just need the script that does all the work to recognise that there's more than one image being uploaded and to name them consecutively etc. I've got the images saved into the web server directory and the database just holds the information about the images. $image_name = $_POST['image_name']; $image_group = $_POST['image_group']; $location_no = $_POST['location_no']; $category_name = $_POST['category_name']; $image_info = $_POST['image_info']; $image_date_taken = $_POST['image_date_taken']; $image_tempname = $_FILES['image_filename']['name']; $today = date("Y-m-d"); $ImageDir ="img/category/"; $ImageThumb = $ImageDir . "thumbnails/"; $ImageName = $ImageDir . $image_tempname; if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $ImageName)) { list($width, $height, $type, $attr) = getimagesize($ImageName); if ($type > 3) { echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file.<br>"; echo "Please hit your browser's 'back' button and try again."; } else { $sql = "INSERT INTO cms_images_category " . "(image_name, image_group, location_no, category_name, image_info, image_date_taken, image_date) " . "VALUES ('" . $_POST['image_name'] . "','" . $_POST['image_group'] . "','" . $_POST['location_no'] . "','" . $_POST['category_name'] . "','" . $_POST['image_info'] . "','" . $_POST['image_date_taken'] . "','" . date("Y-m-d H:i:s", time()) . "')"; mysql_query($sql, $conn) or die('Could not insert content; ' . mysql_error()); $lastpicid = mysql_insert_id(); $newfilename = $ImageDir . $lastpicid . ".jpg"; if ($type == 2) { rename($ImageName, $newfilename); } else { if ($type == 1) { $image_old = imagecreatefromgif($ImageName); } elseif ($type == 3) { $image_old = imagecreatefrompng($ImageName); } $image_jpg = imagecreatetruecolor($width, $height); imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height); imagejpeg($image_jpg, $newfilename); imagedestroy($image_old); imagedestroy($image_jpg); } $newthumbname = $ImageThumb . $lastpicid . ".jpg"; $thumb_width = $width * 0.10; $thumb_height = $height * 0.10; $largeimage = imagecreatefromjpeg($newfilename); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); imagejpeg($thumb, $newthumbname); imagedestroy($largeimage); imagedestroy($thumb); } } redirect('search.php?imageupload=yes&id=' . $lastpicid ); break; Currently only the last image uploaded is saved and registered in the database. Any help would be appreciated. Oh and there is a page that deals with checking of the files after theyve been uploaded which checks for the $lastpicid which will also need to be modified... $id = $_REQUEST['id']; $getpic = mysql_query("SELECT * FROM cms_images_category WHERE image_id = '$id'") or die(mysql_error()); $rows = mysql_fetch_array($getpic); extract($rows); $image_filename = "img/category/" . $image_id . ".jpg"; list($width, $height, $type, $attr) = getimagesize($image_filename); echo " <h3>The image has been uploaded </h3> "; echo " <table><tr>"; echo " <td class ='upload' width='300' rowspan='7'>"; echo " <img src=" . $image_filename . " class =\"uploadimg\"></td>"; echo " <td class ='upload' width='150'>"; echo " <h2>Image Name</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($image_name) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Image Group</h2></td>"; echo " <td class ='upload'>"; echo ' <select name="image_group" size="1" > '; echo ' <optgroup label="-------------------------------------------------">'; $query2 = "SELECT image_groups " . "FROM cms_image_group "; $results2 = mysql_query($query2,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results2)) { extract($row); echo ' <option selected value="' . $image_group . '" selected="selected">'. htmlspecialchars($row['image_groups']); } echo " </option></optgroup>\n"; echo " </select></td><br>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Category</h2></td>"; echo " <td class ='upload'>"; echo ' <select name="category_name" size="1" > '; echo ' <optgroup label="-------------------------------------------------">'; $query3 = "SELECT category_id, category_name " . "FROM cms_categories "; $results3 = mysql_query($query3,$conn) or die(mysql_error()); while ($row = mysql_fetch_array($results3)) { extract($row); echo ' <option selected value="' . $row['category_name'] . '" selected="selected">'. htmlspecialchars($row['category_name']); } echo " </option></optgroup>\n"; echo " </select></td><br>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Location No</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($location_no) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Image info </h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="5" cols="30"> ' . htmlspecialchars($image_info) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Date image taken</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($image_date_taken) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td class ='upload'>"; echo " <h2>Uploaded</h2></td>"; echo " <td class ='upload'>"; echo ' <p><textarea class="body" name="image_info" rows="1" cols="30"> ' . htmlspecialchars($image_date) . "</textarea><br></td>\n"; echo " </tr>"; echo " <tr>"; echo " <td >"; echo ' <input name="id" type="hidden" value= ' . $image_id . ">\n"; echo ' <input type="submit" class="submit" name="action" ' . "value=\"Change Details\"></td>"; echo " </tr>"; echo " </table>"; Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059094 Share on other sites More sharing options...
JAY6390 Posted May 16, 2010 Share Posted May 16, 2010 I would recommend using a pre-built script that already does this http://www.google.com/search?q=multi+image+upload+script+php There's plenty of them out there you could use, and there's far too much code to read through above Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059096 Share on other sites More sharing options...
plugnz Posted May 16, 2010 Author Share Posted May 16, 2010 Thanks for that, I'll look into it. thanks for the code tip too. Hard to know how much code to put up to be the most helpful. Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059234 Share on other sites More sharing options...
litebearer Posted May 16, 2010 Share Posted May 16, 2010 might also look into client simply ftp ing them - close to no brainer as possible Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059241 Share on other sites More sharing options...
plugnz Posted May 16, 2010 Author Share Posted May 16, 2010 Client is not really internet savvy enough to cope with that. whole point of the site is to provide an easy web based platform for him to store and access all his images and for clients to access. Besides its good learning for me so might as well make it as hard as possible for myself! , Ta though. Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059260 Share on other sites More sharing options...
litebearer Posted May 17, 2010 Share Posted May 17, 2010 might take a look at this free script http://www.phphq.net/scripts.php?script=phUploader#phUploader Link to comment https://forums.phpfreaks.com/topic/201943-uploading-mulitple-images/#findComment-1059268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.