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

Home > Pasties > Pastie #14

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

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

 
PHPEdit User Community, © 2008 WaterProof SARL
Powered by PHPEdit