BrighteyesDesign
asked on
View Directory on website using php
I have setup a function for my client to upload files via a php form to a specific directory.
What i need to do is display the directory files on a webpage so my client can see whats been uploaded. Also, if this is possible is it then possible to delete files? (not so important but would be useful)
Thanks
What i need to do is display the directory files on a webpage so my client can see whats been uploaded. Also, if this is possible is it then possible to delete files? (not so important but would be useful)
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hi,
Use this,
Use this,
<?php
$link = "documents";
if(is_link($link)) {
$dir = readlink($link);
if($dh = opendir($dir)) {
while(($file = readdir($dh)) !== false) {
echo "filename: $file -- filetype ".filetype($dir.$file)."\n";
}
closedir($dh);
}
}
?>
try this,
ref. http://php.net/manual/en/function.readdir.php
ref. http://php.net/manual/en/function.readdir.php
<?php
// Note that !== did not exist until 4.0.0-RC2
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
/* This is the WRONG way to loop over the directory. */
while ($file = readdir($handle)) {
echo "$file\n";
}
closedir($handle);
}
?>
ASKER
Thanks all!
ludofulop, I have used that script and the directory contents show fine. They show as a list though, what would i add to the code the have each filename appear on a new line?
thanks
ludofulop, I have used that script and the directory contents show fine. They show as a list though, what would i add to the code the have each filename appear on a new line?
thanks
just replace \n with br in echo command:
echo "filename: $file -- filetype ".filetype($dir.$file)."<b r />"
echo "filename: $file -- filetype ".filetype($dir.$file)."<b
http://sk.php.net/manual/en/function.unlink.php