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

Home > Pasties > Pastie #15

Created on 10/03/2008 08:26 by Anonymous

  1. function CheckFileExtension($file,&$Extension=array())
  2. {
  3.  
  4. if(file_exists($file))
  5. {
  6.  
  7. // ON EXTRAIT L'EXTENSION
  8. $SubstractExt = substr(strrchr($file, "."), 1);
  9.  
  10. // VERIFICATION QUE LE TABLEAU DES EXTENSIONS AUTORISEES EST SOUMIS
  11.  
  12. if(!is_array($Extension) OR (is_array($Extension) AND
    count($Extension) == 0))
  13. {
  14. // Si aucun tableau fourni, ou si le tableau fourni est vide
  15. return false;
  16. }
  17. elseif(in_array(strtolower($SubstractExt),$Extension))
  18. {
  19. // Tout va bien on continue
  20. //return true;
  21. return strtolower($SubstractExt);
  22. }
  23. else{
  24. // Tout autre cas on false
  25. return false;
  26. }
  27.  
  28. }else {
  29. // fichier inexistant, on false
  30. return false;
  31. }
  32. }
  33.  
  34.  
  35. // UTILISATION
  36. $myfile = "options.php";
  37. $AllowedExtensions = array("php","jpg","txt");
  38. $testFile = CheckFileExtension($myfile,$AllowedExtensions);
  39.  
  40. if($testFile == true)
  41. {
  42. echo "L'extention ".$testFile." est prise en charge";
  43. }else{
  44. echo "Désolé le type de fichier n'est pas prise en charge";
  45. }

 
PHPEdit User Community, © 2008 WaterProof SARL
Powered by PHPEdit