Jump to content

scandir, pdf files, magic names


bungee

Recommended Posts

Let me start by saying that I know very little about php but I know enough that I like to tinker.  I have made a small website to be used locally only at my job to make sorting and finding bookmarks more efficiently.  We also have a catalog of pdf files for looking up various stuff that currently are a pain.  I finally got some code going that lists them all with their url.  There are some directories that are giving me fits though.  It seems that it doesn't like the file names of some of the files and instead lists names that aren't there, along with some that are.  I have found that some of the 'made up' names are actually in the title.  An example.  In the directory c:/xampp/htdocs/site/diagrams/mantis there is a file called 7222 sv4b1le.pdf with a title of 400730.TILLER.  On the page it shows a file named 400730.pdf which doesn't exist and doesn't show the 7222 sv4b1le.pdf file in the list.;Does php hate pdf files?  Am I doing something wrong? Please help.  Here is the code.  I left it pretty basic until I get it to do what I want.

 <?php
function scandir_recursive($dir) {
     $items = scandir($dir);
  
     foreach($items as $item) {
         if ($item == '.' || $item == '..') {
             continue;
         }
         $tfile = $dir . '/' . $item;
	$fname = $item;
   if (is_dir($item))
		{
	echo "<h1>$item</h1>";
		}
	else if (is_dir($tfile))
		{
	echo "<h1>$item</h1>";
		}		
	else	{
	$tfile2 = substr($tfile, 7);
         echo "<a href='$tfile2'>$fname</a>------http://127.0.0.1$tfile2<br />";
  }
         if (is_dir($tfile)) {
             scandir_recursive($tfile);
         }
     }
}
  
scandir_recursive('/htdocs/site');
//scandir_recursive('/htdocs/site/diagrams/mantis');
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.