bilis_money Posted June 26, 2006 Share Posted June 26, 2006 hi & hello PHP addicts...hi, i want to read all the files inside a directory and put them in an array.let say i have /photos/ directory and i want to get the files that reside in there and insert theminto array.can you show me the way you do this? your style?I have already an idea with this but i'm just curious to know yours?Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/ Share on other sites More sharing options...
Orio Posted June 26, 2006 Share Posted June 26, 2006 Requires PHP5 [a href=\"http://www.php.net/manual/en/function.scandir.php\" target=\"_blank\"]scandir()[/a]If you have PHP<5, read the user posts below, and you'll find a function for that.Orio. Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/#findComment-49567 Share on other sites More sharing options...
litebearer Posted June 26, 2006 Share Posted June 26, 2006 Look at the script on this page, it has a scetion that reads the contents of a folder into an array. works with several versions of php.[a href=\"http://www.nstoia.com/mygallery/\" target=\"_blank\"]http://www.nstoia.com/mygallery/[/a]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/#findComment-49621 Share on other sites More sharing options...
bilis_money Posted June 26, 2006 Author Share Posted June 26, 2006 Thank you very much -->[!--sizeo:4--][span style=\"font-size:14pt;line-height:100%\"][!--/sizeo--] litebearer[!--sizec--][/span][!--/sizec--].Thanks for the link, and by the way is that your personal webiste [b]LITE[/b]? Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/#findComment-49647 Share on other sites More sharing options...
litebearer Posted June 26, 2006 Share Posted June 26, 2006 My pleasure.Yes, my personal site, which is in a state of constant flux as I learn how to do more things.Lite... Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/#findComment-49691 Share on other sites More sharing options...
zq29 Posted June 26, 2006 Share Posted June 26, 2006 the function [a href=\"http://www.php.net/glob\" target=\"_blank\"]glob()[/a] returnsan array of all of the files/directories within a specified directory. Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/#findComment-49699 Share on other sites More sharing options...
Orio Posted June 26, 2006 Share Posted June 26, 2006 I still think that [a href=\"http://www.php.net/manual/en/function.scandir.php\" target=\"_blank\"]scandir()[/a] is the best solution for this one.It's defenition is:[i]List files and directories inside the specified path.Returns an array of files and directories from the directory.[/i]And if you have PHP<5, use this:[code]<?phpif(!function_exists('scandir')) { function scandir($dir, $sortorder = 0) { if(is_dir($dir)) { $dirlist = opendir($dir); while( ($file = readdir($dirlist)) !== false) { if(!is_dir($file)) { $files[] = $file; } } ($sortorder == 0) ? asort($files) : rsort($files); return $files; } else { return FALSE; break; } }}?>[/code]Orio. Quote Link to comment https://forums.phpfreaks.com/topic/12913-reading-files-and-inserting-it-into-an-array/#findComment-49702 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.