Jump to content

Remove file extensions before creating links


farkewie

Recommended Posts

Hello i have some working code here that creats a list of links in the noted directory,

but i would like it to remove file extenions. they are all word docs.

 

also is there a way to force it to open in the browser?

 

all computers will be running latest IE6 and maybe IE 7 in the future.

 


<?php 

$intCounter = 1;
$ref = $_SERVER['PHP_SELF'];
if ($handle = opendir('./cheat_sheets')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "<div id=\"left-panel\"><a href=\"$ref?album=$file\">$file</a></div>";
        }		

    }
    closedir($handle);
}


?>

<?php 

$intCounter = 1;
$ref = $_SERVER['PHP_SELF'];
if ($handle = opendir('./cheat_sheets')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
		$file = substr($file, 0, -(strlen($file)-(strrpos($file, "."))));
            echo "<div id=\"left-panel\"><a href=\"$ref?album=$file\">$file</a></div>";
        }		

    }
    closedir($handle);
}


?>

 

 

As for forcing the browser to open the doc file instead of prompting to download it, you can send the following header:

header("Content-type: application/msword");

And then echo the contents of the file (see readfile()).

 

Orio.

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.