farkewie Posted November 8, 2007 Share Posted November 8, 2007 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); } ?> Link to comment https://forums.phpfreaks.com/topic/76487-remove-file-extensions-before-creating-links/ Share on other sites More sharing options...
Orio Posted November 8, 2007 Share Posted November 8, 2007 <?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. Link to comment https://forums.phpfreaks.com/topic/76487-remove-file-extensions-before-creating-links/#findComment-387422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.