I have some scripts read the file names in directorys. when I get the file names back I want to strip off the extension with I display the info to the browser. like I have 10_6541.jpg and I want to display just 10_6541.
Here is the code I'm using to get the file names
<?
$file_path = "Albums_pgg/"; //dir
$what_file = "/.+.(gif$|jpg$|jpeg$)/i"; // what file? (reg ex)
$pics = addfiles($file_path,$what_file,$with_subdirs);
echo implode("<br>",$pics);
function addfiles($path,$what_file,$with_subdirs)
{
global $files;
$files[0] = "";
$handle = @opendir($path);
while ($file = @readdir ($handle)) {
if ($file != "." && $file != ".."){
if (preg_match($what_file , $file)) $files[] = $file; // addfile
}
}
@rewinddir ($handle);
@closedir($handle);
unset ($files[0]);
return $files;
}
?>