Created
August 21, 2019 15:04
-
-
Save enqtran/e6f349feb424e9940022a3e2aebd5e50 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Inspecting a Folder with scandir() | |
Ex: $files = scandir('../images'); | |
Inspecting the Contents of a Folder with FilesystemIterator | |
Ex: $files = new FilesystemIterator('../images'); | |
getFilename() The name of the file | |
getPath() The current object’s relative path minus the filename, or minus the folder name if the current object is a folder | |
getPathName() The current object’s relative path, including the filename or folder name, de-pending on the current type | |
getRealPath() The current object’s full path, including filename if appropriate | |
getSize() The size of the file or folder in bytes | |
isDir() True, if the current object is a folder (directory) | |
isFile() True, if the current object is a file | |
isReadable() True, if the current object is readable | |
isWritable() True, if the current object is writable | |
Restricting File Types with the RegexIterator | |
$files = new FilesystemIterator('.'); | |
$files = new RegexIterator($files, '/\.(?:txt|csv)$/i'); | |
foreach ($files as $file) { | |
echo $file->getFilename() . '<br>'; | |
} | |
Creating a Download Link | |
Ex: readfile($path); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment