Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Upload obrazków na serwer[miniaturki]
--Sergio--
post 9.05.2013, 11:51:29
Post #1





Goście







Witam
Mam o to taki skrypt uploadu zdjęć na serwer. Skrypt ma wrzucić obrazek do katalogu 'photo/tmp' a następnie pomniejszony ten obrazek do folderu 'photo'.
Normalne zdjęcie do folderu 'photo/tmp' wrzuca poprawnie, lecz pomniejszony obrazek w folderze photo jest cały czarny.
Jak to poprawić

  1. if(is_uploaded_file($_FILES['girl_photo']['tmp_name'])){
  2.  
  3. $type=end(explode("/",$_FILES['girl_photo']['type']));
  4. $filename="photo/tmp/".$fileName.'.jpg';
  5. if(!move_uploaded_file($_FILES['girl_photo']['tmp_name'],$filename)){
  6. echo 'error';
  7. }
  8.  
  9. list($oldWidth, $oldHeight) = getimagesize($filename);
  10.  
  11. $ratio=400/$oldWidth;
  12.  
  13. $newWidth=400;
  14. $newHeight=$oldHeight*$ratio;
  15.  
  16. $cutHeight=floor(($newHeight-400)/2);
  17.  
  18. echo $newWidth.'<br>';
  19. echo $newHeight.'<br>';
  20. //exit();
  21.  
  22.  
  23. switch($type) {
  24. case 'jpeg':
  25. $org = imagecreatefromjpeg($filename);
  26. break;
  27. case 'gif':
  28. $org = imagecreatefromgif($filename);
  29. break;
  30. case 'png':
  31. $org = imagecreatefrompng($filename);
  32. break;
  33. }
  34.  
  35.  
  36. $image_p = imagecreatetruecolor($newWidth, $newHeight);
  37. $image = imagecreatefromjpeg($filename);
  38. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $newWidth, $newGeight, $oldWidth, $oldHeight);
  39.  
  40. $filename2="photo/".$fileName.'.jpg';
  41. imagejpeg($image_p, $filename2, 100);
  42. }
Go to the top of the page
+Quote Post
hubson87
post 9.05.2013, 12:43:40
Post #2





Grupa: Zarejestrowani
Postów: 83
Pomógł: 8
Dołączył: 9.02.2011
Skąd: Wrocław

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


masz literówkę w 38 linii $newGeight
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.06.2025 - 17:45