Jump to content

Newbie Help on file lists


nofxsapunk

Recommended Posts

Like I said, I am a newbie when it comes to php. I'm still learning but I catch on quick.

 

Problem:

What I am trying to do is to create a page which will automatically generate a list on files listed in a directory creating a link from the filename; if a file gets deleted then that line of text/link will get deleted, if a file gets uploaded to that directory then a new text/link will be created from the filename.

 

Purpose:

I want to be able to add and delete files from a specific directory on my web page, I then want to have a page that I can go to to get a list of all that is in that folder which stays up to date.

 

Research: I found a few topics on this forum which I beleave are in the same ballpark that I want to be in but I dont know what part of the scripts need to be updated with my websites information. Attached is a script that I found which I belive is sort of what I am looking for.

 

function Get_Directory_Listing( $dir )
{

if( is_dir( $dir ) )
{
	//This is added so that it can enter & list the sub-directories nicely
	if( (substr( $dir, -1) !== "/") || (substr( $dir, -1) !== "\\") )
		$dir .= "\\";

	//This is the main function, whereby it enters the folders and list their contents	
	if( $dir_open = opendir( $dir ) )
	{
		while( ( $file = readdir( $dir_open ) ) !== false )
		{
			if( $file == "." || $file == ".." )
				continue;

			if( filetype( $dir . $file ) == "dir")
			{
				echo "<BR><BR><b>Directory found : $dir$file </b>";
				//if( substr(
				Get_Directory_Listing( $dir . $file  );
			}
			echo "<BR>Filename : $file,  filetype : " . filetype( $dir . $file );
		}
	}
	closedir( $dir_open );
}
else
{
	//This is incase the user forgets to put the semicolon after the drive letter
	$dir .= ":";
	echo "<BR>Drive to be listed : $dir";
	Get_Directory_Listing( $dir );
}
}

http://www.phpfreaks.com/forums/index.php/topic,117672.0.html

 

 

Link to comment
https://forums.phpfreaks.com/topic/51866-newbie-help-on-file-lists/
Share on other sites

I created a PHP file with the attached link and im doing something wrong because it still is not working.

 

$dir = "http://www.hekaent.com/folder";
$dh = opendir($dir) or die("Could not open dir");
while (!(($file = readdir($dh)) === false) )
	{
	echo '<a href="'.$dir.'/'.$file.'">'.$file.'</a>';
	}

 

do I need to put in the URL for the destination needed as shown or do I put in

 

$dir = "local_path/public_html/folder";
$dh = opendir($dir) or die("Could not open dir");
while (!(($file = readdir($dh)) === false) )
	{
	echo '<a href="'.$dir.'/'.$file.'">'.$file.'</a>';
	}

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.