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