lixid Posted November 5, 2006 Share Posted November 5, 2006 i was wondering if there was a dynamic way to list (ex. image.jpg ) images in a folder and then list them in a page as hyperlinks ... also would like to have thumbnail images in there and as long as they have a tn_ before the image name then it would pick that up as a thumbnail image and show the thumbnail. but in short words i would like to be able to just upload images into a folder and throw the script in there and have it be able to pick up the images in that folder and display them dynamicly .. im not asking for the code to do this .. but i am wondering how i would start ... thanx .. :] Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/ Share on other sites More sharing options...
tet3828 Posted November 5, 2006 Share Posted November 5, 2006 Im new to this myself but I'd start by making yourself a database in mySQL. As far as the thumbnails you would either have to use Photoshop to run a batch conversion on all the images you need OR get some sort of 3rd party script that makes thumbnails for you. Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-119855 Share on other sites More sharing options...
Ben Phelps Posted November 5, 2006 Share Posted November 5, 2006 You can name it index.php and it will load the images or you can add it to existing code.Here is a demo of the exact code below http://osphp.net/lixid/[code]<?phpif ($handle = opendir('./images')) { // './filedir' while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "<p><a href='./images/$file'><img src='./images/$file' width='150' height='150' border='0' /></a><br /><a href='./images/$file'>$file</a></p>\n"; } } closedir($handle);}?>[/code]And here is a version that I added a little style to http://osphp.net/lixid/styled.phpHope this helps :) Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-119861 Share on other sites More sharing options...
buttercupgreen Posted November 5, 2006 Share Posted November 5, 2006 Hi, this link shows you how to list files in a dir and exclude directories.you can download the whole php code at the bottom of this page.[url=http://www.dev-tips.org/index.php?title=list_of_files]http://www.dev-tips.org/index.php?title=list_of_files[/url] Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-119885 Share on other sites More sharing options...
Kelset Posted November 5, 2006 Share Posted November 5, 2006 Here is a function that I have found and use, it gets all the images from a directory and passesit back as an array. You can then loop through the array and make your link or what have you.function getImagesList($path) { $ctr = 0; if ( $img_dir = @opendir($path) ) { while ( false !== ($img_file = readdir($img_dir)) ) { // can add checks for other image file types here if ( preg_match("/(\.gif|\.jpg)$/", $img_file) ) { $images[$ctr] = $img_file; $ctr++; } } closedir($img_dir); return $images; } return false;}cheers!Stephen Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-119889 Share on other sites More sharing options...
lixid Posted November 5, 2006 Author Share Posted November 5, 2006 thanx so much .. i kinda had a visual of what the code would look like but couldnt quite get it out of my head... i really appreciate all the replies this helps alot .. thanx again .. :] Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-120009 Share on other sites More sharing options...
Stooney Posted November 5, 2006 Share Posted November 5, 2006 just thought I might add a bit, you can also you .htaccess to list a directory. The previous posts are probably best, just thought I'd throw this one out there. http://www.clockwatchers.com/htaccess_dir.html (kinda ugly tutorial, but it works.) Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-120015 Share on other sites More sharing options...
Nicklas Posted November 5, 2006 Share Posted November 5, 2006 If you use PHP5, use [url=http://www.php.net/scandir]scandir()[/url] Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-120082 Share on other sites More sharing options...
heckenschutze Posted November 5, 2006 Share Posted November 5, 2006 Kelset's method is rather 'slow', since regular expressions are memory intensive, if you had say 1 million images in the directory... it'll take a while...use the [url=http://php.net/glob]glob()[/url] function. Link to comment https://forums.phpfreaks.com/topic/26211-php-code-to-list-files-in-a-dir/#findComment-120092 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.