Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Friendly File Viewer - Full Code [Not Help]
Old 06-29-2010, 05:27 PM Friendly File Viewer - Full Code [Not Help]
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
PHP Code:
$directory "docs/";
$SpecialList "yes"//Deternime if Custom Formatting
if ($SpecialList=="yes") {
  
$DispStart "<ul style='list-style:circle;margin:0px;'>";  //Standard Unordered List comes prepackaged! :D
  
$DispFormat "<li style='margin:-5px;'>";
  
$DispFormat2 "</li>";
  
$DispEnd "</ul>";
}
  echo 
"<h1>Oops!</h1><p>You haven't specified which article you want to look at!</p><p>Here's a list of what files I've found for you, maybe one of them will be what you are looking for.</p>";
  if (
is_dir($directory)) {
      if (
$dirOpen=opendir($directory)) {
      while ((
$fileTR=readdir($dirOpen))!=false) {
       echo 
$DispStart;
        if (
filetype($directory.$fileTR)!="dir") {
          
$ridOfFExt=array(".php"=>"",".txt"=>"",".htm"=>"",".html"=>"");
          echo 
"$DispFormat<a href='$directory$fileTR'>".strtr(preg_replace("([A-Z]+)"" $0"$fileTR),$ridOfFExt)."</a>$DispFormat2<br />";
        }
       echo 
$DispEnd;
      }
      
closedir($dirOpen);
      }
    echo 
"<p>Please note that the files above will not be formatted.  You will see the entire file.  Thank you.</p>";
  }
  else {
    echo 
"Invalid Directory.";
  } 
So basically what this does is display all the files in a specified directory, and lets you go to them. It's useful for error pages, where it says 'File not found, but here's what I DID find' kind of thing.

Hopefully somebody finds it useful!


How it works:

It works by opening the specified directory (using the $directory variable) and reading out the contents using a PHP function. It then formats the name from say, RandomFile.htm to Random File. It also provides a link to RandomFile.htm.

It senses capital letters and replaces them with a space. Now instead of getting the standard ugly NOT FOUND Apache message, you can use this!

Update 1.1 - You can now choose 'yes' or 'no' in the '$SpecialList' variable. You can edit start points, middle points, and end points, so you can easily make in an unordered list, an ordered list, a div... Anything!
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 06-29-2010 at 08:59 PM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Reply     « Reply to Friendly File Viewer - Full Code [Not Help]
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10841 seconds with 12 queries