Télécharger ang Scandir iso, utf8

Éditeur : Laurent1133   +
Mise à jour le : 09/03/2011  ·   Licence : Gratuit  ·   Téléchargé 42 fois   ·   2 Ko
Présentation
array _scandir( $path, $option, $encodage )

option 'a' : tri croissant
option 'z' : tri décroissant
option '.xxx' : filtre uniquement cette extention
option '.' filtre les fichiers sans extention
encodage UTF8 ou ISO : (conversion caratères) optionnel

retourne false en cas d echec.
retourne un tableau array( 'd'=>repertoires, 'f'=>fichiers )
Téléchargement :






		
  1. <?PHP
  2. /**
  3. * récupère le contenu d un repertoire v2.6
  4. *
  5. * array _scandir( $path, $option, $encodage )
  6. *
  7. * option 'a' : tri croissant
  8. * option 'z' : tri décroissant
  9. * option '.xxx' : filtre uniquement cette extention
  10. * option '.' filtre les fichiers sans extention
  11. *
  12. * encodage UTF8 ou ISO : (conversion caratères) optionnel
  13. *
  14. * retourne false en cas d echec.
  15. * retourne un tableau array( 'd'=>repertoires, 'f'=>fichiers )
  16. * Si aucun répèrtoire/fichier NULL est retourné.
  17. */
  18.  
  19. define( 'UTF8', 1, true );
  20. define( 'ISO', 2, true );
  21.  
  22. function _scandir( $path = NULL , $option = NULL, $encodage = NULL ){
  23.  
  24. if( is_null( $path ) || empty( $path ) ){
  25. $path = dirname( __FILE__ );
  26. }
  27.  
  28. $path = rtrim( $path, '\\' );
  29. $path = rtrim( $path, '/' );
  30. $path = $path.'/';
  31.  
  32. $scan = @scandir( $path );
  33.  
  34.  
  35. if( $scan == false ){
  36. $scan = @scandir( utf8_decode( $path ) );
  37. }
  38. if( $scan == false ){
  39. $scan = @scandir( utf8_encode( $path ) );
  40. }
  41. if( $scan == false ){
  42. trigger_error( '* _scandir => path error *', E_USER_WARNING );
  43. return false;
  44. }
  45.  
  46. unset( $scan[ array_search( '.', $scan ) ] );
  47. unset( $scan[ array_search( '..', $scan ) ] );
  48.  
  49. $rep = array( 'd'=>array(), 'f'=>array() );
  50.  
  51. $option = strtolower( $option );
  52. $ext = NULL;
  53.  
  54. if( strlen( $option ) > 1 || $option == '.' ){
  55. $ext = trim( $option, '.' ) ;
  56. $option = 1;
  57. }
  58.  
  59. foreach( $scan as $k=>$el ){
  60.  
  61. switch( $encodage ){
  62. case 1:
  63. $el = utf8_encode( $el );
  64. break;
  65. case 2:
  66. $el = utf8_decode( $el );
  67. }
  68.  
  69. if( is_dir( $path.$el ) ){
  70. array_push( $rep['d'], $el );
  71. }else{
  72.  
  73. if( $ext == NULL && $option != 1 ){
  74. array_push( $rep['f'], $el );
  75. }
  76. else{
  77. if( $ext == pathinfo( $path.strtolower( $el ) , PATHINFO_EXTENSION ) ){
  78. array_push( $rep['f'], $el );
  79. }
  80. }
  81. }
  82.  
  83. }
  84.  
  85. switch( $option ){
  86. case 'a':
  87. natcasesort( $rep['d'] );
  88. natcasesort( $rep['f'] );
  89. break;
  90. case 'z':
  91. natcasesort( $rep['d'] );
  92. natcasesort( $rep['f'] );
  93. $rep['d'] = array_reverse( $rep['d'] );
  94. $rep['f'] = array_reverse( $rep['f'] );
  95. }
  96.  
  97. if( !isset( $rep['d'][0] ) || $option == 1 ){
  98. $rep['d'] = NULL;
  99. }
  100. if( !isset( $rep['f'][0] ) ){
  101. $rep['f'] = NULL;
  102. }
  103.  
  104. return $rep;
  105. }
  106. ?>
Developpez.com décline toute responsabilité quant à l'utilisation des différents éléments téléchargés.

Connexion

Identifiant
Mot de passe
S'inscrireMot de passe oublié ?
 
 
 
 
Partenaires

Hébergement Web