xyn Posted September 13, 2007 Share Posted September 13, 2007 Hey. I'#m currently on 4.4.7 at work, and I'm used to 5. anyway I am tryin to allow local files to be browsed. and I'm having problems with listing and linking the directories My current code will list files and folders, but will not hyperlink them :S Anyone knwo of a php 4 function? or a way around this? <? if(!$i = $_GET['i']) { # Default directory $i = "C:"; } if($handle = opendir($i)) { # Open the specified directory (default: root) while (false !== ($file = readdir($handle))) { if(is_dir($file)) { echo("+ <a href=\"/test.php?i=$i/$file/\">$file</a><br>"); } else { # Display Files echo(" -- $file.<br>"); } } } else{ echo("cannot open dir"); } ?> thanks Quote Link to comment https://forums.phpfreaks.com/topic/69198-solved-show-files-dir/ Share on other sites More sharing options...
madspof Posted September 13, 2007 Share Posted September 13, 2007 This is what i did not sure if it will work for you. Also you will need to forward the directory to this script. If you see as a temporary measure i have made the varaible $dir <?php if(!$i = $_GET['i']) { # Default directory $i = "C:"; } $dir = "test"; if($handle = opendir($dir)) { # Open the specified directory (default: root) while (false !== ($file = readdir($handle))) { if(is_dir($file)) { echo("+ <a href=\"/test.php?i=$i/$file/\">$file</a><br>"); } else { # Display Files echo(" -- <a href=\"$dir/$file\">$file</a><br>"); } } } else{ echo("cannot open dir"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69198-solved-show-files-dir/#findComment-347797 Share on other sites More sharing options...
xyn Posted September 13, 2007 Author Share Posted September 13, 2007 Nope. But I fixed it by this; thanks anyway <? if(!$i = $_GET['i']) { # Default directory $i = "C:"; } if($handle = opendir($i)) { # Open the specified directory (default: root) while (false !== ($file = readdir($handle))) { $files[] = $file; } $num_files = count($files); for($x=0; $x<$num_files; $x++) { # Loop the files from array if( (!$i) && ($files[$x] != '.') || ($files[$x] != '..') ) { # Remove the . or .. from the root $p = preg_match("/\b.\b/", $files[$x]); if(!$p) { # Directory echo("+ $files[$x]<br>"); } else { # File echo("- $files[$x]<br>"); } } } } else{ echo("cannot open dir"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69198-solved-show-files-dir/#findComment-347800 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.