Listing a directory.

This is a discussion on "Listing a directory." within the PHP Forum section. This forum, and the thread "Listing a directory. are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Closed Thread
 
LinkBack Thread Tools
  #1  
Old Aug 29th, 2004, 06:23
Junior Member
Join Date: Jul 2004
Location: USA
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Listing a directory.

I was wondering if any of you had a link to a tutorial for listing all the pictures in a directory? Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Aug 31st, 2004, 10:42
Highly Reputable Member
Join Date: Jul 2003
Location: Ipswich, UK
Posts: 690
Thanks: 0
Thanked 0 Times in 0 Posts
Using what language?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old Aug 31st, 2004, 12:38
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
If you want to do this in PHP then let me know as I can dig out the code...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Aug 31st, 2004, 12:56
Highly Reputable Member
Join Date: Aug 2003
Location: Australia
Posts: 662
Thanks: 0
Thanked 0 Times in 0 Posts
No way.. Go for JSP. It looks SO cool to see page.JSP!!!! lol, I love it... :razz: . heh..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old Aug 31st, 2004, 19:38
Junior Member
Join Date: Jul 2004
Location: USA
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah, it's php. I hate using javascript. I know how to do it if the files have sequential numbers after. I want it so it gets every file no matter what the file name. And Jpg's, Gif,s and Png's. If you could show me how to do this I'd definitely appreciate it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #6  
Old Aug 31st, 2004, 22:04
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
This is the code you need...
Code: Select all
<?

// Name of this file
$thisfile = "imagebrowse.php";

echo "<h1>Directory Listing</h1>\n";

$count == "1";

// The directory our files (images) are stored in
$images_directory = opendir("../images/");

// Setup a loop to link through all the files in the directory
while($filename = readdir($images_directory))
	{
	// We need to eliminate this file (if it's in the same directory)
	// along with . and .. (this dir and go up a dir)
	if ($filename == $thisfile OR $filename == "." OR $filename == "..") {
	}
	else {
	 // All these others are files
    	 echo("
<a href=\"http://$fullurl/admin/images/$filename\" target=\"_blank\">$filename</a>\n");
	 $count=substr_count($filename,".");
	 
	 if ($count == "1" && $filename != ".") {
	 if (isset($showimages)) {
	 echo "
<img src=\"http://$fullurl/admin/images/$filename\">
\n";
	 }
		echo "";
		echo(filesize($filename));
		echo(" Bytes
\n");
		
	 }
	 else {
	 }
	}
	$count++;
}

closedir($images_directory);

?>
That will show the text names and file sizes of all files in that particular directory specified.

Also bear in mind that I used a variable $fullurl which isn't declared in the code. Replace it or declare it for yourself.

Obviously you can tweak the code so that it displays the actual images, or whatever you like.

It's also possible to filter files by their extension, but I'll let you try to figure that our for yourself first.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #7  
Old Aug 31st, 2004, 22:14
Junior Member
Join Date: Jul 2004
Location: USA
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks. All I really needed to know what the readdir and closedir statements. Otherwise the language is just like C++.. so I can figure out most things as long as in know the logic behind it. I'm gonna try to put a list of images at the top of my picture gallery and when you click on 1 in the top Iframe the image in the other frame changes. Should be a fun few hours.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #8  
Old Nov 19th, 2004, 21:11
Reputable Member
Join Date: Aug 2003
Location: Singapore
Posts: 321
Thanks: 0
Thanked 0 Times in 0 Posts
Why not just open the directory usig opendir() function and then use while to loop through. Then run a while with its expression to assign its readdir result to another variable. Within while, if the directory has a directory in it, print a hard-coded "D" and then print the file names inside, using the file variable. Then use closedir to close it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Tags
listing, directory

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Directory listing using PHP djeyewater PHP Forum 4 Apr 2nd, 2008 17:09
#1 (permalink) Free Listing To PR3 Web Design Directory! No recip! vcsonline Link Building and Link Sales 0 May 29th, 2007 13:43
Listing website Kwabena Website Planning 3 May 14th, 2007 21:14
Listing files in a folder ismilelots PHP Forum 5 Feb 15th, 2007 18:49
Business listing povidiu Link Building and Link Sales 0 Sep 21st, 2006 09:41


All times are GMT. The time now is 09:43.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42