how to select all files from folder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aamir_rak
Forum Newbie
Posts: 3
Joined: Wed Jul 13, 2011 12:53 am

how to select all files from folder

Post 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...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: how to select all files from folder

Post 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
(#10850)
aamir_rak
Forum Newbie
Posts: 3
Joined: Wed Jul 13, 2011 12:53 am

Re: how to select all files from folder

Post 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";
}
}
Post Reply