Jump to content

Renaming Directory files for DISPLAY


Dale Thompson

Recommended Posts

Hey guys I'm at my wits end, I have being searching around for a way to display files in one directory but when they get displayed to have them named something else, hell even just dropping the extension would be good.

 

my code is as follows.

 

<?
$path = "historyh/";
$narray=array();
$dir_handle = @opendir($path) or die("Unable to open $path");
echo "";
$i=0;
while($file = readdir($dir_handle))
{
    if(is_dir($file))
    {
        continue;
    }
    else if($file != '.' && $file != '..')
    {
        //echo "<a href='$path/$file'>$file</a><br/>";
        $narray[$i]=$file;
        $i++;
    }
}
rsort($narray);

for($i=0; $i<sizeof($narray); $i++)
{
echo "<a href=".chr(34).$path.$narray[$i].chr(34).">".$narray[$i]."</a><br/><br/>";

}

//closing the directory
closedir($dir_handle);
?>

 

 

I looked around and found the split function but apparently that doesnt work anymore. so any ideas ??

Link to comment
https://forums.phpfreaks.com/topic/195653-renaming-directory-files-for-display/
Share on other sites

i am struggling to understand the concept of what you want to do.

 

display a file with a different name. your code is showing you want to output <a> links to the file. so... if you are planning on linking to a filename other than by the file's name itself, do you want to temporarily make a copy of the file with a different filename and then generate links to the temporary files?

 

from what i understand of your code, you are just reading a directory listing of filenames (no directory names or . or ..) into an array and then looping through the array outputting links to the filenames.

i am struggling to understand the concept of what you want to do.

 

display a file with a different name. your code is showing you want to output <a> links to the file. so... if you are planning on linking to a filename other than by the file's name itself, do you want to temporarily make a copy of the file with a different filename and then generate links to the temporary files?

 

from what i understand of your code, you are just reading a directory listing of filenames (no directory names or . or ..) into an array and then looping through the array outputting links to the filenames.

 

Correct, what I am doing is simply uploading daily tips to a horse racing tips site and rather then actually doing it manually for the boss I decided if display each file in the directory as a link all I would have to do is upload a template page with the content included from some where else, this way he can do it without changing anything major in the designs. but what he wants is to have the file displayed for instance 20100317.php but come out as 20100317 in the link.

 

sorry if it doesn't make sense I haven't slept for a while lol and php is not my foray.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.