This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

PHP Check Image Types

By: a guest on Oct 11th, 2010  |  syntax: PHP  |  size: 0.94 KB  |  views: 77  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function checkjpeg($filename) {
  2.         $filesize = filesize($filename);
  3.         $fres = fopen($filename,"r");
  4.         if ($fres == false) { return false;}
  5.         $fstart = bin2hex(fread($fres,2));
  6.         fseek($fres, $filesize-2);
  7.         $fend = bin2hex(fread($fres,2));
  8.         fclose($fres); 
  9.         if ($fstart == "ffd8" && $fend == "ffd9") {
  10.                 return true;
  11.         } else {
  12.                 return false;
  13.         }
  14.  
  15. }
  16.  
  17. function checkpng($filename) {
  18.         $filesize = filesize($filename);
  19.         $fres = fopen($filename,"r");
  20.         if ($fres == false) { return false;}
  21.         $fstart = bin2hex(fread($fres,8));
  22.         fclose($fres); 
  23.         if ($fstart == "89504e470d0a1a0a") {
  24.                 return true;
  25.         } else {
  26.                 return false;
  27.         }
  28.  
  29. }
  30.  
  31.  
  32. function checkgif($filename) {
  33.         $filesize = filesize($filename);
  34.         $fres = fopen($filename,"r");
  35.         if ($fres == false) { return false;}
  36.         $fstart = bin2hex(fread($fres,6));
  37.         fclose($fres);
  38.        
  39.         if ($fstart == "474946383961" || $fstart == "474946383761") {
  40.                 return true;
  41.         } else {
  42.                 return false;
  43.         }
  44. }
clone this paste RAW Paste Data