PHPEdit.net Community
   
1 2 3 4
Tutorials Tips Pasties Code Snippets
 

Home > Pasties > Pastie #3

Created on 23/01/2008 15:02 by Sebastien Hordeaux

  1. function validate_extension($filename, $validExtensions = array('zip',
    'rar', 'jpg', 'jpeg', 'gif', 'bmp'))
  2. {
  3. // find the last dot inside the filename
  4. $dotPos = strrpos($filename, '.');
  5. // if no dot was found, the extension is not valid
  6. if (false === $dotPos) {
  7. return false;
  8. }
  9. // get the extension, be sure the dot is not included, and be sure
    the
  10. // string gets to lowercase
  11. $extension = substr($filename, ($dotPos + 1));
  12.  
  13. $extension = strtolower($extension);
  14. // when the extension is inside the array, it is valid
  15. return in_array($extension, $validExtensions);
  16. }
  17.  

 
PHPEdit User Community, © 2008 WaterProof SARL
Powered by PHPEdit