Jump to content

Recommended Posts

Hello!

 

Im trying to do a simple gallery where a simple script gets all images from a folder and puts them into a line of small thumbs. Each picture links to itself and displays it as a bigger one below the smaller ones.. This script also gets rows from a textfile and uses it as a description for the image depending on what picture you display.. 1.jpg, 2.jpg and so on.

 

For example:

I have a folder called "bilder" where I put all my pictures (1.jpg, 2.jpg and so on..). I use a script that gets all the pictures from the folder and lines them up in a row as small pictures/thumbs 40x40 pixels. I also put a link on them that links to the same picture. It links to the same page but with "?pic_id=1" and displays the picture I just clicked on below the row of thumbs.. but here is where my problem is: I dont know how to get right numbers on the right thumbs.

 

My thought was that I somehow could use the names 1.jpg, 2.jpg and remove the ".jpg" and use the numbers to link to the right picture. Or is it possible to implement some sort of count-feature that puts the right "link number" on the right picture?

For example, on the first picture 1.jpg it links to ?pic_id=1, and 2.jpg links to ?pic_id=2 and so on.. which way is the easiest? and how do I do it?

 

This is what I use so far:

 


//Folder where I have my pictures
$path = "bilder/";

//using the opendir function
$dir_handle = @opendir($path) ;

//running the while loop
while ($file = readdir($dir_handle)) {	
   	if($file!="." && $file!="..")
      
echo "<a href='?pic_id=".$[color=red]????[/color]."'><img src='$path/$file' border='0' width='40' height='40'/></a> ";}

closedir($dir_handle);

 

Is this possible to solve?

 

It would be easier to implement a $count variable

$path = "bilder/";
$dir_handle = @opendir($path) ;
$count = 1;
while ($file = readdir($dir_handle)) {	
   	if($file!="." && $file!=".."){
      echo "<a href='?pic_id=".$count."'><img src='".$path."/".$count.".jpg' border='0' width='40' height='40'/></a> ";
$count++;
}
}
closedir($dir_handle);

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.