login  Naam:   Wachtwoord: 
Registreer je!
 Forum

Meerdere uploads + resize.

Offline WebVisual - 18/08/2005 17:50
Avatar van WebVisualLid Ben bezig met een fotoalbum. Nu het lukt me om meerdere uploads tegelijk te doen maar ze dan nog is allemaal resizen naar opgegeven afmeeting lukt me niet. Het lukt me wel als ik ze 1 per 1 upload dus niet met meerdere. Nu vroeg ik mij af of dit mogelijk was om in dit script te plaatsen. Kan iemand mij even helpen aub?


http://www.site...&id=21

5 antwoorden

Gesponsorde links
Offline Fenrir - 18/08/2005 17:53
Avatar van Fenrir PHP expert Je zet de code om het te resizen in de loop waarmee de bestanden weggeschreven worden.
Offline WebVisual - 18/08/2005 17:54
Avatar van WebVisual Lid Fenrir kan jij mij daar even mee helpen aub?
Offline Fenrir - 18/08/2005 20:12
Avatar van Fenrir PHP expert Als jij de code geeft om 1 foto te resizen. 
Offline Geerios - 18/08/2005 22:17
Avatar van Geerios Onbekend
Citaat:
Als jij de code geeft om 1 foto te resizen. 
Al had je ff hier gekeke: http://www.site...amp;cat=14 en dan hier: http://www.site...amp;id=680 dan had je wel zo'n code kunnen vinden!
Offline WebVisual - 19/08/2005 08:20 (laatste wijziging 19/08/2005 09:45)
Avatar van WebVisual Lid Heb dit gevonden op php.....nl en dit werkt.

Nu heb ik het aangepast en haal ik uit de database de map waar de foto's inkomen. Probleem is dat hij in men select option gewoon de $var weergeeft inplaats van de inhoud.

Aangepaste versie:
  1. <?php
  2. include("../config.php");
  3. $upload_directory = "temp"; // hier word de foto eerst geupload!
  4. $save_dir = $_POST['dir']; // hier word de foto opgeslagen!
  5.  
  6. $max_uploads = "20"; // max uploads
  7.  
  8. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  9. {
  10.  
  11. if(!is_dir($save_dir))
  12. {
  13. mkdir($save_dir);
  14.  
  15. }
  16. if ($_POST['files'])
  17. {
  18. printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload&dir=$save_dir');
  19. for ($i = 1; $i <= $_POST['files']; $i++)
  20. {
  21. printf('<input type="file" name="file_%s" size="100"><br />', $i);
  22. }
  23. printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">');
  24. printf('<input type="submit" value="Upload bestanden">');
  25. printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
  26. printf('</form>');
  27. }
  28. else
  29. {
  30. printf('<h3>Resultaten:</h3>');
  31. printf('Bestanden geupload naar: %s<br /><br />', $upload_directory);
  32. printf('<table border="1">');
  33. for ($i = 1; $i <= $_POST['history_files']; $i++)
  34. {
  35. $tmp_filename = $_FILES['file_'.$i]['tmp_name'];
  36. $filename = $_FILES['file_'.$i]['name'];
  37. if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
  38. {
  39. $status = 'Verzonden...';
  40.  
  41. $up_file = $upload_directory.'/'.$filename;
  42. $srcimage = imagecreatefromjpeg($up_file);
  43. $width = imageSX($srcimage);
  44. $height = imageSY($srcimage);
  45. if($width <= 250 && $height <= 250){
  46. $t_width=$width;
  47. } else {
  48. if ($height < $width){
  49. $t_width = 400;
  50. }
  51. else {
  52. $t_width = 350;
  53. }
  54. }
  55. $newh1= $height / $width;
  56. $newh2= $newh1 * $t_width;
  57. $destimage = imagecreatetruecolor($t_width,$newh2);
  58. imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
  59. ImageJPEG($destimage,'',100);
  60. $buffer = ob_get_contents();
  61. $file=$save_dir.'/'.$filename;
  62. $handle = fopen($file, 'ab');
  63. fwrite($handle, $buffer);
  64. fclose($handle);
  65. $delete=$upload_directory.'/'.$filename;
  66. @unlink($delete);?>
  67. <?
  68. }
  69. else
  70. {
  71. $status = 'Fout!';
  72. }
  73. printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:'&nbsp;', $status);
  74. }
  75. printf('</table>');
  76. }
  77. }
  78. else
  79. {
  80. printf('<form method="post" action="%s">', '?page=admin&link=upload&dir=$save_dir');
  81. printf('Aantal upload velden: ');
  82. printf('<select name="files">');
  83. for ($i = 1; $i <= $max_uploads; $i++)
  84. {
  85. printf('<option value="%1$s">%1$s', $i);
  86. }
  87. printf('</select><br />');
  88.  
  89. printf('Kies album: ');
  90. printf('<select name="dir">');
  91. $query = mysql_query("SELECT * FROM fotoalbum ORDER BY naam ASC") or die(mysql_error());
  92. while($var = mysql_fetch_object($query)) {
  93. printf('<option value="$var->album_id">$var->$naam</option>', $i);
  94. }
  95. printf('</select> <br />');
  96. printf('<input type="submit" value="Creëer velden">');
  97. printf('</form>');
  98. }
  99. ?>


Origineele versie
  1. <?php
  2. $upload_directory = "temp"; // hier word de foto eerst geupload!
  3. $save_dir = "resize"; // hier word de foto opgeslagen!
  4.  
  5. $max_uploads = "20"; // max uploads
  6.  
  7. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  8. {
  9. if ($_POST['files'])
  10. {
  11. printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload');
  12. for ($i = 1; $i <= $_POST['files']; $i++)
  13. {
  14. printf('<input type="file" name="file_%s" size="100"><br />', $i);
  15. }
  16. printf('<input type="button" onclick="javascript: history.back(-1);" value="Cancel">');
  17. printf('<input type="submit" value="Upload bestanden">');
  18. printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
  19. printf('</form>');
  20. }
  21. else
  22. {
  23. printf('<h3>Resultaten:</h3>');
  24. printf('Bestanden geupload naar: %s<br /><br />', $upload_directory);
  25. printf('<table border="1">');
  26. for ($i = 1; $i <= $_POST['history_files']; $i++)
  27. {
  28. $tmp_filename = $_FILES['file_'.$i]['tmp_name'];
  29. $filename = $_FILES['file_'.$i]['name'];
  30. if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
  31. {
  32. $status = 'Verzonden...';
  33.  
  34. $up_file = $upload_directory.'/'.$filename;
  35. $srcimage = imagecreatefromjpeg($up_file);
  36. $width = imageSX($srcimage);
  37. $height = imageSY($srcimage);
  38. if($width <= 250 && $height <= 250){
  39. $t_width=$width;
  40. } else {
  41. if ($height < $width){
  42. $t_width = 400;
  43. }
  44. else {
  45. $t_width = 350;
  46. }
  47. }
  48. $newh1= $height / $width;
  49. $newh2= $newh1 * $t_width;
  50. $destimage = imagecreatetruecolor($t_width,$newh2);
  51. imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
  52. ImageJPEG($destimage,'',100);
  53. $buffer = ob_get_contents();
  54. $file=$save_dir.'/'.$filename;
  55. $handle = fopen($file, 'ab');
  56. fwrite($handle, $buffer);
  57. fclose($handle);
  58. $delete=$upload_directory.'/'.$filename;
  59. @unlink($delete);?>
  60. <?
  61. }
  62. else
  63. {
  64. $status = 'Fout!';
  65. }
  66. printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:'&nbsp;', $status);
  67. }
  68. printf('</table>');
  69. }
  70. }
  71. else
  72. {
  73. printf('<form method="post" action="%s">', '?page=admin&link=upload');
  74. printf('Aantal upload velden: ');
  75. printf('<select name="files">');
  76. for ($i = 1; $i <= $max_uploads; $i++)
  77. {
  78. printf('<option value="%1$s">%1$s', $i);
  79. }
  80. printf('</select> ');
  81. printf('<input type="submit" value="Creëer velden">');
  82. printf('</form>');
  83. }
  84. ?>
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.21s