note 85985 modified in function.readdir by danbrown
| From: | danbrown@php.net | Date: | Sat, 27 Sep 2008 00:34:36 +0000 |
| Subject: | note 85985 modified in function.readdir by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144828@lists.php.net to get a copy of this message | ||
<?php
//getting all files of desired extension from the dir using explode
$desired_extension = 'pdf'; //extension we're looking for
$dirname = "uploads/";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
$fileChunks = explode(".", $file);
if($fileChunks[1] == $desired_extension) //interested in second chunk only
{
echo 'a href="uploads/'.$file.'" target="_blank">
'.$file.'</a></br>';
}
}
}
closedir($dir);
?>
--was--
//getting all files of desired extension from the dir using explode
$desired_extension = 'pdf'; //extension we're looking for
$dirname = "uploads/";
$dir = opendir($dirname);
while(false != ($file = readdir($dir)))
{
if(($file != ".") and ($file != ".."))
{
$fileChunks = explode(".", $file);
if($fileChunks[1] == $desired_extension) //interested in second chunk only
{
echo 'a href="uploads/'.$file.'" target="_blank">
'.$file.'</a></br>';
}
}
}
closedir($dir);
http://php.net/manual/en/function.readdir.php