TGWSE_GY Posted July 15, 2009 Share Posted July 15, 2009 I am needing to know if I have a directory called 'images' how I would recursively just load the file names 'imagename.jpg' into an array of key => values and the keys being incremental integers. I know this should probably be easy but as I am just learning about directories and how to interact with them. Any help would be great! Thanks Guys Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 15, 2009 Share Posted July 15, 2009 Look at the glob function. Ken Quote Link to comment Share on other sites More sharing options...
TGWSE_GY Posted July 15, 2009 Author Share Posted July 15, 2009 I appreciate the help Ken, but as I am completley unsure of what is going to be stored in the directory at all times I guess it is my lack in understanding directories to arrays that makes glob() seem un-helpful. Can you give me an example or another method that may help me better understand the process. Thanks George! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 16, 2009 Share Posted July 16, 2009 The best way to see what the function does is to create a small script and run it: <?php $files = glob('path/to/your/images/*.jpg'); echo '<pre>' . print_r($files,true) . '</pre>'; // this will dump the array to the screen so you can see what's in it foreach ($files as $fn) { // loop through the array to get each file echo '<a href="' . $fn . '">' . $fn . "</a><br>\n"; // put a link to each file on the page } ?> Put this script on your server and when run, it will give you a list of the images as links. Click on each link to see the picture. Ken Quote Link to comment 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.