Ok... so I have this code which reads all the folders and files within the path
$path = getcwd();
read_dir($path);
}
function read_dir($dir) {
$path = opendir($dir);
while (($element = readdir($path)) !== false) {
if($element != "." && $element != "..") {
if(is_dir($dir."/".$element)) {
$dirs[]=$dir."/".$element; // put all folders in CWD into an array
$folders[] = $element;
}
if(is_file($dir."/".$element)) {
$files[]=$element; // put all files in CWD into an array
}
}
}
if($dirs) {
foreach($dirs as $dir) echo "$dir<br>";
read_dir($dir); // call function again to read sub dirs
}
if($files) {
foreach ($files as $file) echo "$file<br>";
}
closedir($path);
}
?>
this works fine. BUT!
this code will read all the dirs, and if there are sub dirs read them. When there are no more sub dirs, THEN it reads the files.
I want to read a folder and then the files in that folder.
What i'm trying to do:
I have a tree of folders/sub folders with pics. I want to read through them and write the foldername and filename to the database.
So, i think to do this i need to read the folder and then the files in it right after.
INSERT foldername,filename into table
I need the correct folder variable when reading the files.