Witam,

Mam napisany taki skrypt jak można go uprościć by był bardziej optymalny, bezpieczny.

  1. <?php
  2. if (isset($_POST['dodaj'])) {
  3. $ilosc_foto = trim($_POST['ilosc_foto']);
  4. $kat = trim($_POST['kat']);
  5.  
  6. <p><b>Dodawanie Fotografii</b></p>
  7. <p>';
  8.  
  9. $max_no_img=$ilosc_foto; // Maximum number of images value to be set here
  10. print "<form method=post enctype='multipart/form-data'>";
  11. print "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>";
  12. for($i=1; $i<=$max_no_img; $i++){
  13. print "<tr><td>Zdjecie $i</td><td>
  14. <input type='file' name='images[]' class='bginput'></td></tr>";
  15. }
  16. print '</table></p>
  17. <div class="pagesPrzyciski" style="margin-left:120px; margin-top:10px;">
  18. <input type="hidden" name="kat" value="'.$kat.'" />
  19. <input type="submit" name="addimg" class="pages" value="Wyślij" />
  20. <input type="reset" class="pages" value="Resetuj" />
  21. <input type="button" class="pages" onclick="java script:history.back();" name="wstecz" value="Wstecz" />
  22. </div>
  23. </form> ';
  24.  
  25.  
  26. }
  27. elseif(isset($_POST['addimg'])) {
  28.  
  29. $kat = trim($_POST['kat']);
  30.  
  31. while(list($key,$value) = each($_FILES['images']['name']))
  32. {
  33.  
  34. if(!empty($value))
  35. {
  36. $filename = $value;
  37. $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
  38. $ext = pathinfo($filename, PATHINFO_EXTENSION);
  39.  
  40. $zapytanie = "INSERT foto VALUES ('', '$ext', '$kat')";
  41. $wstaw = mysql_query($zapytanie);
  42. $id = mysql_insert_id();
  43.  
  44. $kodowanie = $id;
  45. $lacz = $kodowanie.".".$ext;
  46. $add = "../uploads/foto/$lacz";
  47. //echo $_FILES['images']['type'][$key];
  48. // echo "<br>";
  49. copy($_FILES['images']['tmp_name'][$key], $add);
  50.  
  51.  
  52. $max_width = 800;
  53. $max_height = 600;
  54.  
  55. $proporcja = $max_width / $max_height;
  56.  
  57. $format = $ext;
  58.  
  59. if($format== "png"){$zdjecie = imagecreatefrompng("../uploads/foto/".$lacz);}
  60. if($format== "jpg"){$zdjecie = imagecreatefromjpeg("../uploads/foto/".$lacz);}
  61. if($format== "gif"){$zdjecie = imagecreatefromgif("../uploads/foto/".$lacz);}
  62.  
  63. $proporcja_zdjecia = imagesx($zdjecie) / imagesy($zdjecie);
  64.  
  65. $nowe_zdjecie = imagecreatetruecolor($max_width, $max_height);
  66.  
  67. if($proporcja_zdjecia > $proporcja)
  68. {
  69. //$srodek = $proporcja/imagesy($zdjecie);
  70. $srodek = (imagesx($zdjecie) - imagesx($zdjecie)/$proporcja ) / 4;
  71. imagecopyresampled($nowe_zdjecie, $zdjecie, 0, 0, $srodek, 0,
  72. $max_width, $max_height, imagesy($zdjecie)*$proporcja,
  73. imagesy($zdjecie) );
  74. }
  75. else
  76. {
  77. $srodek = (imagesy($zdjecie) - imagesy($zdjecie)/$proporcja ) / 4;
  78. //$srodek = imagesx($zdjecie)*$proporcja;
  79. imagecopyresampled($nowe_zdjecie, $zdjecie, 0, 0, 0, $srodek,
  80. $max_width, $max_height, imagesx($zdjecie),
  81. imagesx($zdjecie)/$proporcja );
  82. }
  83.  
  84.  
  85.  
  86.  
  87. if($format== "png"){imagepng($nowe_zdjecie, "../uploads/foto/photo/".$lacz);}
  88. if($format== "jpg"){imagejpeg($nowe_zdjecie, "../uploads/foto/photo/".$lacz);}
  89. if($format== "gif"){imagegif($nowe_zdjecie, "../uploads/foto/photo/".$lacz);}
  90.  
  91. $max_width = 145;
  92. $max_height = 120;
  93.  
  94. $proporcja = $max_width / $max_height;
  95.  
  96. $format = $ext;
  97.  
  98. if($format== "png"){$zdjecie = imagecreatefrompng("../uploads/foto/".$lacz);}
  99. if($format== "jpg"){$zdjecie = imagecreatefromjpeg("../uploads/foto/".$lacz);}
  100. if($format== "gif"){$zdjecie = imagecreatefromgif("../uploads/foto/".$lacz);}
  101.  
  102. $proporcja_zdjecia = imagesx($zdjecie) / imagesy($zdjecie);
  103.  
  104. $nowe_zdjecie = imagecreatetruecolor($max_width, $max_height);
  105.  
  106. if($proporcja_zdjecia > $proporcja)
  107. {
  108. //$srodek = $proporcja/imagesy($zdjecie);
  109. $srodek = (imagesx($zdjecie) - imagesx($zdjecie)/$proporcja ) / 4;
  110. imagecopyresampled($nowe_zdjecie, $zdjecie, 0, 0, $srodek, 0,
  111. $max_width, $max_height, imagesy($zdjecie)*$proporcja,
  112. imagesy($zdjecie) );
  113. }
  114. else
  115. {
  116. $srodek = (imagesy($zdjecie) - imagesy($zdjecie)/$proporcja ) / 4;
  117. //$srodek = imagesx($zdjecie)*$proporcja;
  118. imagecopyresampled($nowe_zdjecie, $zdjecie, 0, 0, 0, $srodek,
  119. $max_width, $max_height, imagesx($zdjecie),
  120. imagesx($zdjecie)/$proporcja );
  121. }
  122.  
  123.  
  124.  
  125.  
  126. if($format== "png"){imagepng($nowe_zdjecie, "../uploads/foto/mini/".$lacz);}
  127. if($format== "jpg"){imagejpeg($nowe_zdjecie, "../uploads/foto/mini/".$lacz);}
  128. if($format== "gif"){imagegif($nowe_zdjecie, "../uploads/foto/mini/".$lacz);}
  129.  
  130. unlink("../uploads/foto/".$lacz."");
  131.  
  132. }
  133. else print'Dodawanie nieudane.';
  134. }
  135. print'<div id="dymkaP">Brawo udało Ci się dodać fotografie.</div>';
  136.  
  137. }


Proszę o pomoc, chodzi o uproszczenie by skrypt był mniejszy oraz bezpieczniejszy.