lorne17 Posted November 25, 2008 Share Posted November 25, 2008 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. Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/ Share on other sites More sharing options...
jordanwb Posted November 25, 2008 Share Posted November 25, 2008 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> Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/#findComment-698313 Share on other sites More sharing options...
lorne17 Posted November 25, 2008 Author Share Posted November 25, 2008 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? Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/#findComment-698633 Share on other sites More sharing options...
lorne17 Posted November 25, 2008 Author Share Posted November 25, 2008 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 ?? Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/#findComment-698635 Share on other sites More sharing options...
bluesoul Posted November 25, 2008 Share Posted November 25, 2008 Have you tried.. $root = $_SERVER['DOCUMENT_ROOT']; // defined outside the loop $thelist .= '<a href="'.$root.'/'.$file.'">'.$root.'/'.$file.'</a>'.'<br>'; Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/#findComment-698753 Share on other sites More sharing options...
flyhoney Posted November 25, 2008 Share Posted November 25, 2008 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); } ?> Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/#findComment-698755 Share on other sites More sharing options...
lorne17 Posted November 26, 2008 Author Share Posted November 26, 2008 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 Link to comment https://forums.phpfreaks.com/topic/134137-solved-link-to-specific-folder-directory/#findComment-699240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.