Jump to content

Recommended Posts

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 them
into 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.

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...
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]<?php
if(!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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.