1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
//Création de un ou plusieurs répertoires imbriqués (l'index 0 sera la racine), retourne un tableau ou une variable
function G_path_directory($name_directory, $droits = 0755) {
if(is_array($name_directory)) {
$new_directory = "./";
foreach($name_directory as $directory) {
@mkdir($new_directory.$directory, $droits);
$new_directory .= $directory."/";
$tab_directory[] = $new_directory;
}
return $tab_directory;
}
else {
@mkdir($name_directory, $droits);
return $name_directory."/";
}
}
//Lit tous les fichiers d'un répertoire puis les retourne, peut appliquer un filtre si le type est fourni (ex "jpg")
function Read_file_directory($path_directory, $type = false) {
if(is_dir($path_directory)) {
$directory = dir($path_directory);
$files = array();
if($type != false) {
$glob = glob($path_directory."/*.".$type);
foreach($glob as $name) {
$tab_name = explode("/", $name);
$nbr_max = count($tab_name);
$files[] = $tab_name[$nbr_max - 1];
}
}
else {
while($name = $directory->read()) $files[] = $name;
}
return $files;
}
else {
return;
}
} |
Partager