Jump to content

[SOLVED] Show files/ dir


xyn

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/69198-solved-show-files-dir/
Share on other sites

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"); }
?>

Link to comment
https://forums.phpfreaks.com/topic/69198-solved-show-files-dir/#findComment-347797
Share on other sites

Nope. But I fixed it by this; thanks anyway :D

 

<?
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"); }
?>

Link to comment
https://forums.phpfreaks.com/topic/69198-solved-show-files-dir/#findComment-347800
Share on other sites

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.