I made this to represent a directory tree in an array that uses the file or directory names as keys and full paths as the value for files. Directories are nested arrays. Unless you specify no sorting, file names are sorted in ASCII alphabetic order, meaning numbers first, then uppercase, then lowercase letters, even on operating systems whose file system ignores the case of file names when it does its own sorting. For example, on Mac OS, the following files will appear in this order in the Finder, when your disk is formated using the standard file system: 1file.
I wrote this function to read a folder and place all the folders and sub folders it contains into an array. Back in the saddle of scandir I wrote this function for a function that I needed to seperate directories from files. Since I am still learning from my last example way below I would figure I would add it so it can be criticized.
Here is such a function. By default, this function will keep in memory the scandir result, to avoid scaning multiple time for the same directory. Requires at least PHP5. Since scandir returns and array, here is a more concise method of dealing with the '.
Previous PHP rmdir Function. Next Java lang. Recommended Articles. Article Contributed By :. Easy Normal Medium Hard Expert. Writing code in comment? Please use ide. Load Comments. What's New. Viewed 77k times.
Improve this question. Community Bot 1 1 1 silver badge. Mark Lalor Mark Lalor 7, 17 17 gold badges 64 64 silver badges bronze badges.
Add a comment. Active Oldest Votes. Improve this answer. Gras Double Matthew Matthew 46k 11 11 gold badges 84 84 silver badges 97 97 bronze badges. Oh wow Compare this to the behemoth above. Here's a function that I have used to get a nice simple array of all incoming files from a page.
Note that this function loses the file input names I usually process the files just by type. In checking the error code, you probably ought to check for code 4. I believe Code 4 means no file was uploaded, and there are many instances where that's perfectly OK. Such as when you have a form with multiple data items, including file and image uploads, plus whatever else. The user might not be adding a new upload for whatever reason, such as there may already be a file in the system from an earlier update, and the user is satisfied with that.
Try Again. For quick debugging eg. Obviously don't use these for comparison in real code. Nontypicall array comes in php after the submission.
0コメント