Posted by : Anjana Jayaweera Thursday, November 7, 2013

1. How to read folder name in PHP


$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

/* Do your magic here */

echo $foldername;

}
Don't forget to add '/*' after your folder name
2. How to read file names in a folder in PHP

$folderpath = "./FOLDER-NAME/*.*";

foreach(glob($folderpath) as $filename){

/* Do your magic here */

echo $filename;

}
Don't forget to add '/*.*' after your folder name

Might you will complain that it is reading the whole path, not the folder/ filename you want to get at the end. So follow this trick. :)

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

$newFolderName = str_replace("./FOLDER-NAME/", '', $foldername);

echo $newFolderName;

}
TaDa !!!!

Leave a Reply

Subscribe to Posts | Subscribe to Comments

Popular Post

Blogger templates

Labels

- Copyright © My Code Genius by 2 Geniuses -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -