Page 1 of 1
how to select all files from folder
Posted: Wed Jul 13, 2011 12:59 am
by aamir_rak
hi guys,
i have folder containing all pdf files i want to display their name on php page and when i click any of it, it will open so kindly help me in this regards how can i do this,
it is very urgent for me
waiting fro your replies...
Re: how to select all files from folder
Posted: Wed Jul 13, 2011 1:11 am
by Christopher
Probably glob() would be the easiest way, but there are several other ways to read directories.
http://www.php.net/manual/en/function.glob.php
Re: how to select all files from folder
Posted: Wed Jul 13, 2011 4:35 am
by aamir_rak
thanks for reply i am using that code but their is problem in opening the pdf file
//echo "<select name=\"file\">\n";
foreach (new DirectoryIterator('D:/paper_less/finance/Investment Consultative Group.') as $file) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if ( (!$file->isDot()) && ($file->getFilename() != basename($_SERVER['PHP_SELF'])) ) {
// echo "<option>";
// if the element is a directory add to the file name "(Dir)"
?>
<a href="file:///D://paper_less/finance/Investment%20Consultative%20Group/<?php echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename(); ?>"><?php echo ($file->isDir()) ? "(Dir) ".$file->getFilename() : $file->getFilename(); ?> </a> <?php
// echo "</option>\n";
}
}