Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Wysyłanie obrazków na serwer, Wysyłanie obrazków na serwer
Vion
post
Post #1





Grupa: Zarejestrowani
Postów: 112
Pomógł: 2
Dołączył: 27.06.2008

Ostrzeżenie: (0%)
-----


Witam
Mam o to taki formularz do wysyłania obrazków, oraz skrypt który przetwarza obrazek(tworzy jego miniaturę). I teraz jak zrobić abym mógł wysłać 6 plików graficznych za pomocą jednego formularza.

  1. <form method="post" action="upload.php" enctype="multipart/form-data">
  2. <input name="image_filename1" type="file" size="29"><br><br>
  3. <input type="submit" value="Dodaj">
  4. </form>


  1. <?php
  2.  
  3.  
  4. $image_filename1 = $_FILES['image_filename1']['name'];
  5. $image_size = $_FILES['image_filename1']['size'];
  6. $ImageDir= "photo/";
  7. $ImageThumb = $ImageDir . "thumbs/";
  8. $ImageName= $ImageDir . $image_filename1;
  9.  
  10.  
  11. if (empty($image_filename1)) {
  12. $error .="Musisz+wybrac+plik+graficzny<br>";
  13. }
  14.  
  15.  
  16.  
  17. list($width, $height, $type) = getimagesize($_FILES['image_filename1']['tmp_name']);
  18. if ($image_size > 2097152) {
  19. $error .="Rozmiar+pliku+graficznego+nie+moze+przekraczac+2MB<br>";
  20. }
  21. if($width >1280) {
  22. $error .="Szerokosc+obrazka+nie+moze+byc+wieksza+niz+1280+pikseli";
  23. }
  24. if($height >800) {
  25. $error .="Wysokosc+obrazka+nie+moze+byc+wieksza+niz+1280+pikseli";
  26. }
  27.  
  28. if ($type > 3) {
  29. $error .=ulrencode("Przykro+nam+ale+poday+obraz+jest+w+zlym+formacie+!");
  30. }
  31. if (empty($error)) {
  32. if (move_uploaded_file($_FILES['image_filename1']['tmp_name'], $ImageName)) {
  33.  
  34.  
  35. $lastpicid = 1;
  36. $newfilename = $ImageDir . $lastpicid . ".jpg";
  37.  
  38. if ($type == 2) {
  39. rename($ImageName, $newfilename);
  40. } else {
  41. if ($type == 1) {
  42. $image_old = imagecreatefromgif($ImageName);
  43. } elseif ($type == 3) {
  44. $image_old = imagecreatefrompng($ImageName);
  45. }
  46.  
  47. $image_jpg = imagecreatetruecolor($width, $height);
  48. imagecopyresampled($image_jpg, $image_old, 0, 0, 0, 0, $width, $height, $width, $height);
  49. imagejpeg($image_jpg, $newfilename);
  50. imagedestroy($image_old);
  51. imagedestroy($image_jpg);
  52.  
  53. }
  54. //**WSTAW NASTĘPUJˇCE WIERSZE
  55. $newthumbname = $ImageThumb . $lastpicid . ".jpg";
  56.  
  57. // pobierz wymiary miniaturki
  58. $width_thumb= 94;
  59. $height_thumb= 70;
  60.  
  61.  
  62. // utwórz miniaturkę
  63. $largeimage = imagecreatefromjpeg($newfilename);
  64. $thumb = imagecreatetruecolor($width_thumb, $height_thumb);
  65. imagecopyresampled($thumb, $largeimage, 0, 0, 0, 0,
  66. $width_thumb, $height_thumb, $width, $height);
  67. imagejpeg($thumb, $newthumbname);
  68. imagedestroy($largeimage);
  69. imagedestroy($thumb);
  70.  
  71.  
  72.  
  73. }}
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 19:12