Jump to content

[SOLVED] Link to specific folder directory


lorne17

Recommended Posts

Hello there,

 

I am trying to get this to work.  I have php code in my file and it automatically lists the folder contents.  What I need to do is have these folder linked to open the contents of the folders shown.

 

That may not make sense...here:

<?php
if ($handle = opendir('client login files')) {
   $ignore_files = array('.', '..', '.htaccess', '.htpasswd', 'index.php', 'uploader.php', '~template');
   while (false !== ($file = readdir($handle)))
      {
          if (!in_array($file, $ignore_files))
     {
             $thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>';
          }
       }
  closedir($handle);
  }
?>

 

This line here:

$thelist .= '<a href="'.$file.'">'.$file.'</a>'.'<br>';

is where the link isn't working.  It thinks it's opening the folder in the root directory, when really I need to have this linked to contents in a subfolder in my root directory.

 

Does that make sense?  Any help would be greatly appreciated.

 

 

It thinks it's opening the folder in the root directory, when really I need to have this linked to contents in a subfolder in my root directory.

 

So instead of being:

 

<a href="foo.com/bar/folder">Link</a>

 

is it

 

<a href="foo.com/folder">Link</a>

Well sort of.  What my goal is, is to get the list of folders in the directory: foo.com/folder automatically listed with this php code.  Then the list will automatically link to index.php inside each folder.  Since foo.com/folder only has more folders in it, no individual files. 

 

That is why I used: '.$file.' as the link.  But when I use that the link it places in the automatic list goes to the root.  So let's say I have foo.com/folder in the page and it lists it's contents.  The folders listed are:

Project 1

Project 2

Project 3

 

Now when I click that link that my php code created.  It goes to: foo.com/Project 1.  When really it should be foo.com/folder/Project 1.  Then if the link goes to the correct folder it automatically loads index.php that is located in the Project folders.

 

Does that make sense what I'm trying to accomplish?

Also for the record I changed this code.  The code in my first post is wrong:

 

if ($handle = opendir('.')) {

 

Maybe it's this code that needs the extra location help.  Do I need to add the folder name here to direct it to: foo.com/folder ??

Is this what you mean?

 

<?php
$dir = 'client login files';
if ($handle = opendir($dir)) {
   $ignore_files = array('.', '..', '.htaccess', '.htpasswd', 'index.php', 'uploader.php', '~template');
   while (false !== ($file = readdir($handle)))
      {
          if (!in_array($file, $ignore_files))
     {
             $thelist .= '<a href="'.$dir.'/'.$file.'">'.$file.'</a>'.'<br>';
          }
       }
  closedir($handle);
  }
?>

Hey,

 

That worked great!  Thanks so much, exactly what I wanted.

 

Here's my code:

<?php
$dir = 'client login files';
if ($handle = opendir($dir)) {
   $ignore_files = array('.', '..', '.htaccess', '.htpasswd', 'index.php', 'uploader.php', '~template');
   while (false !== ($file = readdir($handle)))
      {
          if (!in_array($file, $ignore_files))
     {
             $thelist .= '<a href="'.$dir.'/'.$file.'">'.$file.'</a>'.'<br>';
          }
       }
  closedir($handle);
  }
?>
<p style="font-weight: bold; font-size: 10pt">List of files:</p>
<p style="font-weight: bold; font-size: 10pt; color: #560D1C"><?=$thelist?></p>

 

 

Thanks again,

Lorne

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.