insejn Posted November 5, 2009 Share Posted November 5, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/180471-organize-pictures-from-a-folder-with-number/ Share on other sites More sharing options...
flattened Posted November 5, 2009 Share Posted November 5, 2009 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); Quote Link to comment https://forums.phpfreaks.com/topic/180471-organize-pictures-from-a-folder-with-number/#findComment-952121 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.