Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [php] jak usunac komunikat warning
Forum PHP.pl > Forum > PHP
AndyPSV
  1. Warning: Division by zero in C:\Program Files\WebServ\httpd\th.php on line 7
  2. Warning: Division by zero in C:\Program Files\WebServ\httpd\th.php on line 9
  3. Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\Program Files\WebServ\httpd\th.php on line 16
  4. Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in C:\Program Files\WebServ\httpd\th.php on line 18
  5. Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'http://localhost/v/1/' is not a valid JPEG file in C:\Program Files\WebServ\httpd\th.php on line 18
  6. Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Program Files\WebServ\httpd\th.php on line 19
  7. Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\Program Files\WebServ\httpd\th.php on line 54
  8. Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\WebServ\httpd\th.php:7) in C:\Program Files\WebServ\httpd\th.php on line 71


wstawienie @ przed kodem (include) nic nie daje, error_reporting(0); tak samo nic.
ma ktos jakas solucje ?
nospor
Dzielisz przez zero. Nie uczyli cie na matematyce ze NIE WOLNO dzielic przez zero?

Musisz dac warunek i jesli wymiar ma zero to masz zareagowac odpowiednio
AndyPSV
chodzi o to, ze odpalam skrypt, ktory tworzy miniaturke ze zdjec; jednak problem sie pojawia wtedy kiedy przy pewnych zdjeciach miniaturki nie moga po prostu zostac zrobione... ale mimo to pojawiaja sie jako zdjecia (sa zdjeciami)

wiec, jest jakas solucja ?
nospor
No napisalem ci przeciez: jesli zero to nie dziel

To samo z pozostalymi komunikatami: jesli zero to nie rob image... cos tam.

O IF w php slyszales?

a jesli to nie twoj skrypt, to albo go popraw recznie, albo nie dawaj mu blednych danych
a najlepiej pokaz ten skrypt smile.gif
AndyPSV
sa 2 skrypty:

jeden to:
  1. <?php
  2.  
  3. function imagecopyresampledselection($filename, $desired_width = 100, $desired_height, $bordersize, $position)
  4. {
  5. // Get new dimensions
  6. list($width, $height) = getimagesize($filename);
  7. if($desired_width/$desired_height > $width/$height):
  8. $new_width = $desired_width;
  9. $new_height = $height * ($desired_width / $width);
  10. else:
  11. $new_width = $width * ($desired_height / $height);
  12. $new_height = $desired_height;
  13. endif;
  14.  
  15. // Resize
  16. $image_p = imagecreatetruecolor($new_width, $new_height);
  17. $image_f = imagecreatetruecolor($desired_width, $desired_height);
  18. $image = imagecreatefromjpeg($filename);
  19. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  20.  
  21. // Adjust position
  22. switch($position)
  23. {
  24. case("topleft"):
  25. $x = $bordersize;
  26. $y = $bordersize;
  27. break;
  28.  
  29. case("topright"):
  30. $x = $new_width - $desired_width + $bordersize;
  31. $y = $bordersize;
  32. break;
  33.  
  34. case("bottomleft"):
  35. $x = $bordersize;
  36. $y = $new_height - $desired_height + $bordersize;
  37. break;
  38.  
  39. case("bottomright"):
  40. $x = $new_width - $desired_width + $bordersize;
  41. $y = $new_height - $desired_height + $bordersize;
  42. break;
  43.  
  44. case("center"):
  45. $x = ($new_width - $desired_width) / 2 + $bordersize;
  46. $y = ($new_height - $desired_height) / 2 + $bordersize;
  47. break;
  48. }
  49.  
  50. // Resample with 1px border
  51. imagecopyresampled($image_f, $image_p, $bordersize, $bordersize, $x, $y,  $desired_width - 2 * $bordersize, 
  52. $desired_height - 2 * $bordersize, 
  53. $desired_width - 2 * $bordersize, 
  54. $desired_height - 2 * $bordersize);
  55.  
  56. return $image_f;
  57. }
  58.  
  59. if(!ctype_digit($_GET['w'])) die('Hacking Attempt...');
  60. if(!ctype_digit($_GET['h'])) die('Hacking Attempt...');
  61. if(!ctype_digit($_GET['id'])) die('Hacking Attempt...');
  62.  
  63. # id [[user]]
  64. # title [[filename]]
  65. # filename [[path]]
  66. # w
  67. # h
  68. # ext
  69.  
  70. $image_f = imagecopyresampledselection($_GET['fileName'], $_GET['w'], $_GET['h'], 1, "center");
  71. header('Content-type: image/jpeg');
  72. imagejpeg($image_f, 'v/'.$_GET['id'].'/'.$_GET['title'].'.'.$_GET['w'].'x'.$_GET['h'].'.'.$_GET['ext'], 100);
  73.  
  74. ?>


  1. <?php
  2.  
  3. // if(!ctype_digit($_GET['w'])) die('Hacking Attempt...');
  4. // if(!ctype_digit($_GET['id'])) die('Hacking Attempt...');
  5.  
  6. # id [[user]]
  7. # title [[filename]]
  8. # filename [[path]]
  9. # w
  10. # ext
  11.  
  12. define('THUMBNAIL_SIZE', $_GET['w']);
  13.  
  14. if (!isset($_GET['fileName']) ||
  15. !file_exists($_GET['fileName']))
  16. die();
  17. $pathInfo = pathinfo($_GET['fileName']);
  18. if ($pathInfo['extension'] == 'jpg')
  19. $pathInfo['extension'] = 'jpeg';
  20. if (!function_exists(($fName =
  21. 'imagecreatefrom'.$pathInfo['extension'])))
  22. die();
  23.  
  24. $imgHandle = $fName($_GET['fileName']);
  25. $ratio = ($imgW = imagesx($imgHandle)) /
  26. ($imgH = imagesy($imgHandle));
  27. if ($ratio > 1) {
  28. $newImgW = THUMBNAIL_SIZE;
  29. $newImgH = THUMBNAIL_SIZE / $ratio;
  30. } else {
  31. $newImgW = THUMBNAIL_SIZE * $ratio;
  32. $newImgH = THUMBNAIL_SIZE;
  33. }
  34. $newImageHandle = imagecreatetruecolor($newImgW,
  35. $newImgH);
  36. imagecopyresampled($newImageHandle, $imgHandle,
  37. 0, 0, 0, 0, $newImgW, $newImgH, $imgW, $imgH);
  38.  
  39. header('Content-type: image/'.$pathInfo['extension']);
  40. $fName = 'image'.$pathInfo['extension'];
  41. $fName($newImageHandle);
  42.  
  43. imagejpeg($newImageHandle, 'v/'.$_GET['id'].'/'.$_GET['title'].'.'.$_GET['w'].'.'.$_GET['ext'] , 100);
  44.  
  45. ?>



nie wiem wlasciwie dlaczego wywalaja one bledy mimo, ze obrazek jest tak naprawde zdjeciem ?! i normalnie dziala, a one piszcza cos (warningi i inne) ?
em1X
skoro php zwraca warning to trzeba dojść dlaczego to robi.. nie można wstawiać @ żeby zagłuszać błędy.. trzeba je znaleźć i poprawić
btw. nie sądzisz chyba, że komuś się będzie ten kod chciało w jakikolwiek sposób analizować ?
Cezar708
zabezpiecz kawałek:
  1. <?php
  2. // Get new dimensions
  3. list($width, $height) = getimagesize($filename);
  4. if($desired_width/$desired_height > $width/$height):
  5. $new_width = $desired_width;
  6. $new_height = $height * ($desired_width / $width);
  7. else:
  8. $new_width = $width * ($desired_height / $height);
  9. $new_height = $desired_height;
  10. endif;
  11. ?>

w taki sposób:
  1. <?php
  2. // Get new dimensions
  3. list($width, $height) = getimagesize($filename);
  4. if (!$desired_height || !$height) {
  5. return false; // wyjdź z funkcji bo dalej i tak się nie wykona skrypt...
  6. }
  7. if($desired_width/$desired_height > $width/$height):
  8. $new_width = $desired_width;
  9. $new_height = $height * ($desired_width / $width);
  10. else:
  11. $new_width = $width * ($desired_height / $height);
  12. $new_height = $desired_height;
  13. endif;
  14. ?>


Cytat(em1X @ 29.05.2008, 16:20:30 ) *
skoro php zwraca warning to trzeba dojść dlaczego to robi.. nie można wstawiać @ żeby zagłuszać błędy.. trzeba je znaleźć i poprawić
btw. nie sądzisz chyba, że komuś się będzie ten kod chciało w jakikolwiek sposób analizować ?


a widzisz... czasem każdy ma dzień pomagania... winksmiley.jpg
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.