paulferree Posted February 23, 2008 Share Posted February 23, 2008 I was wondering if there was a function that would help me create a page that will look at a folder (an image folder, that I predefine) and return all the file names in that folder. Is there a function already made for this, if there isn't how would I go about creating one? I just want to upload my images to a folder and have the php extract them all and display them on the page. Any ideas? Thanks, Paul Link to comment https://forums.phpfreaks.com/topic/92615-function-for-returning-list-of-filenames-in-a-directory/ Share on other sites More sharing options...
Chris92 Posted February 23, 2008 Share Posted February 23, 2008 http://php.net/readdir if($handle = opendir('dir/')) { while(false !== ($file = readdir($handle))) { echo "$file \n"; } closedir($handle); } Link to comment https://forums.phpfreaks.com/topic/92615-function-for-returning-list-of-filenames-in-a-directory/#findComment-474677 Share on other sites More sharing options...
paulferree Posted February 23, 2008 Author Share Posted February 23, 2008 Great!! I should've checked the function reference manual first, I apologize...but this is better than the example given on the PHP site...thanks a lot Chris. Paul Link to comment https://forums.phpfreaks.com/topic/92615-function-for-returning-list-of-filenames-in-a-directory/#findComment-474681 Share on other sites More sharing options...
paulferree Posted February 23, 2008 Author Share Posted February 23, 2008 I was looking at this one BTW: [pre]<?php $dir = "/tmp"; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] = $filename; } sort($files); print_r($files); rsort($files); print_r($files); ?> [/pre] Link to comment https://forums.phpfreaks.com/topic/92615-function-for-returning-list-of-filenames-in-a-directory/#findComment-474682 Share on other sites More sharing options...
Demonic Posted February 23, 2008 Share Posted February 23, 2008 Or you could use "glob" http://php.net/glob Link to comment https://forums.phpfreaks.com/topic/92615-function-for-returning-list-of-filenames-in-a-directory/#findComment-474684 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.