Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 16th, 2010, 01:17 AM
Authorized User
 
Join Date: Feb 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Uploading Mulitple images

Hi there,

Is it possible to modify chapt 7 upload_image to enable multiple images or even a folder full of images?
Thanks in advance
Reply With Quote
  #2 (permalink)  
Old May 16th, 2010, 07:55 AM
Authorized User
 
Join Date: Feb 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I've changed the form to enable 12 images to be selected then uploaded at once. The trick is to get the script to rename them all and save them. Currently it only saves 1 image out of the twelve.
Any thoughts?
Reply With Quote
  #3 (permalink)  
Old May 17th, 2010, 01:41 PM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
Originally Posted by plugnz View Post
Ok, I've changed the form to enable 12 images to be selected then uploaded at once. The trick is to get the script to rename them all and save them. Currently it only saves 1 image out of the twelve.
Any thoughts?
Without seeing any code, my sense is that if you can rename and save 1 image, you've conquered most of the battle already. I'd assume you retrieve the images as some type of array structure, so you simply need to iterate over the array with a for-loop. Then inside the for loop is where your code for the first image goes and the for-loop will make sure that the same code is executed for all items in the array.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Reply With Quote
  #4 (permalink)  
Old May 17th, 2010, 10:28 PM
Authorized User
 
Join Date: Feb 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey there Chronicalmaster1,

thanks for the tip.

heres what I have tried - upload script
PHP Code:
$max_no_img 4;
    
$i 0;
    echo 
"<table >";
    echo 
"<tbody>";
    echo 
"<tr>";
    echo 
"<td valign='top' colspan='3'>";
    echo 
"<h2>Please select an image to upload</h2>\n"
    for(
$i=1$i<=$max_no_img$i++){ 
    echo 
' <input name="image_filename" type="file" id="image_filename" value="' 
           
$imagefilename "\">\n"
           } 
    echo 
"<br></td>"
    echo 
"</tr>";
    echo 
"<tr>"
this only works if all of the browse fields are filled in, and then I still only get 1 image uploaded

if i try to upload just 1 then i get this message..
Quote:
Warning: extract() expects parameter 1 to be array, boolean given in .......on line 181
I've got a similar thing happening to my transact script which is prettymuch as taken out of chapt 7 except for the extra fields.
PHP Code:
 $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;
    
//$limit = count($_POST['image_name'];
    
[color="Red"$max_no_img 12 ;
     for (
$i=0$i<=$max_no_img$i++)
     {[/
color]
      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, category_name, image_date) " .
               
"VALUES ('" $_POST['image_name'] .
               
"','" $_POST['image_group'] . 
               
"','" $_POST['category_name'] . "','" .
               
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_old0000
                         
$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$largeimage0000
                         
$thumb_width$thumb_height$width$height);
      
imagejpeg($thumb$newthumbname);
      
imagedestroy($largeimage);
      
imagedestroy($thumb);
       }
      }
     [
color="Red"] }[/color]
      
redirect('search--3.php?imageupload=yes&id=' $lastpicid );
      break; 
Sorry if theres too much code here.

probably best to tackle 1 thing at a time...
Thanks in advance
Reply With Quote
  #5 (permalink)  
Old May 18th, 2010, 04:58 AM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

:) I absolutely think it would help, especially for that huge transact script. One guildeline I usually use, is if you can remove some code to an include file do it. The less PHP you expose on the web page is generally a good idea, since a client, current/future front-end developer, or anyone else with no PHP experience could muck up the code more easily. That's one way to start organizing it, and just use an include() to restore the functionality to the page. Next start breaking jobs out and encapsulating them, the database access, saving the file, etc. That may help to.

I don't have an obvious solution, I've never worked with image upload controls before. However, I do know that forms use the name attribute when you want to access them during the postback transaction. Only radio buttons can share the name value, and that's because only one radio button can be selected, ie you have a dozen radio buttons in a list, but only the one which gets selected returns a value for that name. Your image fields look like they are set up the same way, however, if you have multiple form fields uploading multiple images you are going to be returning MULTIPLE values for ONE name. It wouldn't surprise me if this is why you're only actually getting one image on the other side. I would guess that each form field needs a unique name, and then in the transact script you can attempt to retrieve the values and the images for each field. Just make sure to cover yourself if there's no value returned for each field because no file was selected for it.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Reply With Quote
  #6 (permalink)  
Old May 18th, 2010, 06:39 AM
Authorized User
 
Join Date: Feb 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

you nailed it there then! added [] to the end of $image_name on the form. Great thanks for your wisdom.
next challenge is to get the checkpage to show all the images just uploaded rather than just the lastpicid...
will keep you posted.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Uploading images in your signature andypandyrox456 Forum and Wrox.com Feedback 3 July 15th, 2010 06:16 AM
Uploading multiple images Adam H-W Classic ASP Basics 0 April 26th, 2007 04:18 AM
uploading Images.. Pallav Servlets 4 November 1st, 2004 04:34 AM
uploading images to server joseph007 Classic ASP Components 0 September 16th, 2004 08:30 AM
Uploading images to a database vivi Classic ASP Basics 3 October 30th, 2003 09:14 PM



All times are GMT -4. The time now is 05:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.