nofxsapunk Posted May 17, 2007 Share Posted May 17, 2007 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 More sharing options...
calabiyau Posted May 17, 2007 Share Posted May 17, 2007 $dir = "path_to_your_directry"; $dh = opendir($dir) or die("Could not open dir"); while (!(($file = readdir($dh)) === false) ) { echo '<a href="'.$dir.'/'.$file.'">'.$file.'</a>'; } That is what I use... Link to comment https://forums.phpfreaks.com/topic/51866-newbie-help-on-file-lists/#findComment-255693 Share on other sites More sharing options...
taith Posted May 17, 2007 Share Posted May 17, 2007 sorry guys... i'm going to simplify that with glob() http://ca3.php.net/manual/en/function.glob.php it'll grab any/all files in a directory with a * and all php files with a *.php... it acts similar to the dos version(i feel old... stop laughing ) Link to comment https://forums.phpfreaks.com/topic/51866-newbie-help-on-file-lists/#findComment-255730 Share on other sites More sharing options...
nofxsapunk Posted May 17, 2007 Author Share Posted May 17, 2007 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>'; } Link to comment https://forums.phpfreaks.com/topic/51866-newbie-help-on-file-lists/#findComment-255939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.