I've been working from the online manual, a few tutorials, and this web site but have a problem I haven't been able to get around.
I'm trying to remove the extension from file names. Currently I have $allphotos = substr($entry, 0, -4); doing the job, but obviously this will only remove three letter extensions and not .jpeg or .html or .script etc...
I've searched the manual forums and google but didn't find a solution I was able to apply in this instance.
Is there a good solution for removing perhaps everything after and including the last period in a filename? Is there an easier solution?
Additionally this is one of my first php scripts and I'm sure someone might have a ideas on how to refine it.
Here is the basic task:
1. Read all file names in a directory and all subdirectories
2. remove all but .php or .html
3. put the path in variable $path file name in $file and drop the extension
4. compare $file to a text file containing a list of file names if it's a match echo some html back
Here's what I have:
<?php
$d = dir("..");
treewalk($d);
$d->close();
function treewalk($t)
{
while($entry=$t->read())
{
if (($entry != '.') && ($entry != '..') && ($entry != 'UserSelections.txt'))
{
if (is_dir($t->path . "/" . $entry))
{
$d = dir($t->path . "/" . $entry);
treewalk($d);
$d->close();
}
if (eregi(".php|.html", $entry))
{
$tempfolder = $t->path . "/" . $entry;
$allphotos = substr($entry, 0, -4);
$folder = dirname($tempfolder) . "/";
$filename = 'top100.txt';
$fp = fopen($filename, "r");
$top100photos = fread($fp, filesize($filename));
fclose($fp);
$file = substr($entry, 0, -4);
if (eregi($allphotos, $top100photos)) {
echo ("<p><a href=\"$folder$file.php\" target=\"RightFrame\"><IMG src=\"$folder../thumbnails/$file.jpg\" border=\"1\" alt=\"$file\" align=\"BOTTOM\"></a></p>");
} else {
}
}
}
}
}
?>
Thanks for any help!
Justin