Jump to content

[SOLVED] "Listing" pictures from folder


web_master

Recommended Posts

hi,

 

I have a pictures in one folder. Picture names is:

 

1_photo.jpg

2_photo.jpg

3_photo.jpg ... 100_photo.jpg ... and more

 

is there some posibility to list (print on screen) pictures without dbase. Mean to do one cycle (while), and list this pictures all, or with some limits.

 

 

thnx

 

web_master

Link to comment
Share on other sites

ok,

 

its work,  I see now, to want more :)

 

this works perfectly, but... what can I do if I want to list only last 10 pictures?

pictures have a id nrs:

1_photo_file.jpg

2_photo_file.jpg

3_photo_file.jpg ... etc ...

 

but I want to list from 200_photo_file.jpg to 290_photo_file.jpg DESC. (mean: order DESC LIMIT 10)

 

<?php
	if ($handle = opendir("up_photo/")) {
		while(false !== ($file = readdir($handle))) {

			if($file != "." && $file != "..") {

			$photoprint = "<img src=\"up_photo/".$file."\" alt=\"\" border=\"0\" width=\"130\"><br><br>\n";

			if(stristr($file, "_th")){$photoprint = "";}

			print $photoprint;
			}
		}
		closedir($handle);
	}
?>

Link to comment
Share on other sites

if ($handle = opendir(DOCROOT . 'global/images/content'))
{
while (false !== ($file = readdir($handle)))
{
//explode the file name by the underscore and check the first element in the array 
//which will be your number at the beginning of the filename.
//then in the conditional check, check to see if the number is in the range you want
//of course this will only work if you standardaize your file names and make sure the
//number is always first in the file name
$numbers = explode('_',$file);
   if	(
		$file !=	'.'
		&&
		$file !=	'..'
&& ($numbers[0]>200) && ($numbers[0]<290)
		)
	{
		echo $file . <br />;
	}
}
    closedir($handle);
}

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.