Jump to content

Help with this upload to do multiple files with foreach loop, cant figure out


mac007

Recommended Posts

Hello, all:

 

I have this single-file upload script which is great, but I am trying to modify it to make it do multiple files. I figured best way was to apply a foreach loop to it, but havent been able how to integrate it.

Can anybody please help!... 

 

See code here:

 

<table width="300" border="1" align="center" cellpadding="20" cellspacing="0">
  <tr>
    <td><form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
      <p>
        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
        <br />
      </p>
      <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
    </form></td>
  </tr>
  <tr>
    <td height="112" align="center" valign="top"><?php
        if(isset($_POST['submit'])){


          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
		  
		  
		   $imagename = rand (). ".jpg" ;
		  
		  
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 750; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

              $save = "images/sml_" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 110; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

            //(this echo line disabled for now) echo "Large image: <img src='images/".$imagepath."'><br>"; 
            echo "<p>Picture uploaded:<br /></p> <img src='images/sml_".$imagepath."'>"; 

        
          }
        }

	?>
        
        
        
        
        
        
         </td>
  </tr>
</table>

 

(edited by kenrbnsn to change <CODE></CODE> to


tags)

 

 

I forgot to mention this upload script a bit long, cause it does a few things, like create thumbs, renames files with ramdom ID's, etc... so I want to have it done to each uploaded file, whatever number of files I decide to add to the upload form. As you'l' see, the form there just shows 1 upload field...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.