A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearLoad list of image from folder - page 1
User InfoPosts
Load list of image from folder#1
I have a folder of images, from 10 to 200, a webpage, a jquery fade and a php script that read folder full of images

Is there any way to make the php script scan a folder, get a list of image (in an array ?) and pass it to jquery script ? (first question)

Now, i can make a xml file from the result php list of files found or make a html <li> from the list in the html. is there ANY other way to do that ? (question #2)

posted date: 2009-04-16 16:31:00


Re: Load list of image from folder#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-16 16:31:01


Re: Load list of image from folder#3
You can(t just pass images as "data" into a JavaScript for display, at least not in a reasonable manner.

posted date: 2009-04-16 16:34:00


Re: Load list of image from folder#4
i think he'd just be wanting the paths to the images.

posted date: 2009-04-16 16:35:00


Re: Load list of image from folder#5
the glob function will scan a folder and return an array:$jpgs = glob("*.jpg");you can then pass it back to jQuery by using JSON:echo json_encode($jpgs);it(d then just be a case of looping through the result, generating the necessary HTML.

posted date: 2009-04-16 16:36:00


Re: Load list of image from folder#6
I see... That was anything but clear in the question.

posted date: 2009-04-16 16:37:00


Re: Load list of image from folder#7
There are far superior, and safer ways to get the directory list (like php.net/manual/en/class.directoryiterator.php#88459), but yes., get the list, and output it to the HTML for Jquery to process and build a gallery.

posted date: 2009-04-16 16:42:00


Re: Load list of image from folder#8
To generate the list items you could use something like this (assuming images is the result of json_encode()): var images = {(image1(:(images/image1.jpg(,(image2(:(images/image2.jpg(}jQuery((#imagelist().empty();jQuery.each(images, function() { jQuery((#imagelist().append((<li>(+this+(</li>();});And make sure you have an unordered/ordered list in the HTML source:<ul id="imagelist"> <li>No images found</li></ul>

posted date: 2009-04-16 17:02:00


Re: Load list of image from folder#9
To continue on from nickf(s excellent answer, this is slightly more robust for images of different types.$imagesDir = (path/to/your/images/(;$images = glob($imagesDir . (*.{jpg,jpeg,png,gif}(, GLOB_BRACE);echo json_encode($images);There are other ways of doing this, but this is the easiest. Note some file systems are case sensitive, so ensure the extension list is matching precisely what you(re after.

posted date: 2009-04-16 17:16:00


Re: Load list of image from folder#10
I added an answer that's sort of a follow up to yours, hope you don't mind Nick.

posted date: 2009-04-16 17:18:00


Re: Load list of image from folder#11
some people seem to understand the question !

posted date: 2009-04-17 02:46:00


Re: Load list of image from folder#12
Why "There are far superior, and safer ways to get the directory list". Some people seem to think glob is fine, please compare both to make me choose wisely !

posted date: 2009-04-17 02:53:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.