Convert SINGLE-file upload into multiple files with foreach loop, cant figure out

Reply

Join Date: Mar 2007
Posts: 63
Reputation: websurfer is an unknown quantity at this point 
Solved Threads: 0
websurfer websurfer is offline Offline
Junior Poster in Training

Convert SINGLE-file upload into multiple files with foreach loop, cant figure out

 
0
  #1
Oct 12th, 2008
Hello, all:

I have this single-file upload script which works great (it's a bit log cause it creates thumbs, unique ID's,e tc), 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 figure out how to integrate that.
Can anybody please help!...

See code here:

  1.  
  2.  
  3. <table width="300" border="1" align="center" cellpadding="20" cellspacing="0">
  4. <tr>
  5. <td><form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
  6. <p>
  7. <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
  8. <br />
  9. </p>
  10. <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
  11. </form></td>
  12. </tr>
  13. <tr>
  14. <td height="112" align="center" valign="top"><?php
  15. if(isset($_POST['submit'])){
  16.  
  17.  
  18. if (isset ($_FILES['new_image'])){
  19. $imagename = $_FILES['new_image']['name'];
  20. $source = $_FILES['new_image']['tmp_name'];
  21.  
  22.  
  23. $imagename = rand (). ".jpg" ;
  24.  
  25.  
  26. $target = "images/".$imagename;
  27. move_uploaded_file($source, $target);
  28.  
  29. $imagepath = $imagename;
  30. $save = "images/" . $imagepath; //This is the new file you saving
  31. $file = "images/" . $imagepath; //This is the original file
  32.  
  33. list($width, $height) = getimagesize($file) ;
  34.  
  35. $modwidth = 750;
  36.  
  37. $diff = $width / $modwidth;
  38.  
  39. $modheight = $height / $diff;
  40. $tn = imagecreatetruecolor($modwidth, $modheight) ;
  41. $image = imagecreatefromjpeg($file) ;
  42. imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
  43.  
  44. imagejpeg($tn, $save, 100) ;
  45.  
  46. $save = "images/sml_" . $imagepath; //This is the new file you saving
  47. $file = "images/" . $imagepath; //This is the original file
  48.  
  49. list($width, $height) = getimagesize($file) ;
  50.  
  51. $modwidth = 110;
  52.  
  53. $diff = $width / $modwidth;
  54.  
  55. $modheight = $height / $diff;
  56. $tn = imagecreatetruecolor($modwidth, $modheight) ;
  57. $image = imagecreatefromjpeg($file) ;
  58. imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
  59.  
  60. imagejpeg($tn, $save, 100) ;
  61.  
  62. //(this echo line disabled for now) echo "Large image: <img src='images/".$imagepath."'><br>";
  63. echo "<p>Picture uploaded:<br /></p> <img src='images/sml_".$imagepath."'>";
  64.  
  65.  
  66. }
  67. }
  68.  
  69. ?>
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. &nbsp;</td>
  77. </tr>
  78. </table>
Last edited by cscgal; Oct 12th, 2008 at 9:48 pm. Reason: Fixed code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC