Forum Moderators: coopster

Message Too Old, No Replies

display certain file types in a folder

how hard can it be?

         

surrealillusions

4:38 pm on Nov 19, 2008 (gmt 0)

10+ Year Member



Ive search high and low (and the middle too) for a solution but im getting nowhere fast.

This must be easy to do right?

I have the following script, but i need it to display pdf files only from that folder. I've figured that the allowed types should be in an array, but how do i use that to display only pdf's? Ive looked at the filetype() function but that came to a dead end.

<?php
$dir = "downloads/files/";
$allowedTypes = array('pdf');

$dh = opendir($dir);
while (($file = readdir($dh)) !== false) {
echo "<a href=\"downloads/?file=$file\">$file</a><br />";
}

closedir($dh);
?>

Thanks

:)

cameraman

4:58 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about:
if(in_array [us2.php.net](strtolower(substr($file,-3)),$allowedTypes)
echo "<a href=\"downloads/?file=$file\">$file</a><br />";

henry0

4:59 pm on Nov 19, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could open your dir
read its content
and use Path info [php.net]
to select only the pdf