Benji_
asked on
PHP List Folders and Sub Folders
hi,
i am trying to write a script where users can upload files via FTP to there designated folders and access them via the web.
i need a way that i can list all files and folders in there home directory via hph so that i can pass the location to a file download script
but im not sure how to get "ALL files and folders listed" in 1 place.
Regars
i am trying to write a script where users can upload files via FTP to there designated folders and access them via the web.
i need a way that i can list all files and folders in there home directory via hph so that i can pass the location to a file download script
but im not sure how to get "ALL files and folders listed" in 1 place.
Regars
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to do that in a recursive way with PHP5 you could use the SPL classes:
http://php.net/manual/en/recursivedirectoryiterator.construct.php
http://php.net/manual/en/recursivedirectoryiterator.construct.php
<?php
$directory = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
while($it->valid()) {
if (!$it->isDot()) {
echo 'SubPathName: ' . $it->getSubPathName() . "\n";
echo 'SubPath: ' . $it->getSubPath() . "\n";
echo 'Key: ' . $it->key() . "\n\n";
}
$it->next();
}
?>
ASKER
Hi,
Using the code below is there a way you can get if its a file or directory.
Best Regards
Using the code below is there a way you can get if its a file or directory.
Best Regards
<?php
$directory = '/tmp';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory));
while($it->valid()) {
if (!$it->isDot()) {
echo 'SubPathName: ' . $it->getSubPathName() . "\n";
echo 'SubPath: ' . $it->getSubPath() . "\n";
echo 'Key: ' . $it->key() . "\n\n";
}
$it->next();
}
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok Thanks,
I canot find how to extract the fileaname from the strings either.
Best Regards
I canot find how to extract the fileaname from the strings either.
Best Regards
The filename from a plain string containing the full path?
This will do the basename() function:
http://php.net/manual/en/function.basename.php
This will do the basename() function:
http://php.net/manual/en/function.basename.php
ASKER
Thanks Guys!
on the other hand, if you just simply want to list content in browser for users to see, just simply take out index file