Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 0.84 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Check image dimensions (height and width) before uploading image using PHP
  2. <?php
  3.  
  4. foreach ($_FILES["files"]["error"] as $key => $error) {
  5. if(
  6. $error == UPLOAD_ERR_OK
  7. && $_FILES["files"]["size"][$key] < 500000
  8. && $_FILES["files"]["type"][$key] == "image/gif"
  9. || $_FILES["files"]["type"][$key] == "image/png"
  10. || $_FILES["files"]["type"][$key] == "image/jpeg"
  11. || $_FILES["files"]["type"][$key] == "image/pjpeg"
  12. ){
  13.  
  14.  
  15. $filename = $_FILES["files"]["name"][$key];
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24. if(HOW TO CHECK WIDTH AND HEIGHT)
  25. {
  26. echo '<p>image dimenssions must be less than 1000px width and 1000px height';
  27. }
  28.  
  29.  
  30. }
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. ?>
  39.        
  40. array getimagesize ( string $filename [, array &$imageinfo ] )
  41.        
  42. $test = getimagesize('../bilder/' . $filnamn);
  43. $width = $test[0];
  44. $height = $test[1];
  45.  
  46. if ($width > 1000 || $height > 1000)
  47. {
  48. echo '<p>iamge is to big';
  49. unlink('../bilder/'.$filnamn);
  50. }