Scan a directory or table in database
I have a question: I have a set of files to make available for download. There is no tree, the file name is already clear, etc.
I have two opportunities to retrieve the file list:
- Place all files in a folder, scan the file and exit the list. And it has the advantage of easily by following the addition of new files (you stick in the folder, and it's good).
- Create a table that indexes all the files, then make a call out the basic list. A little more complicated to maintain thereafter, add an entry for each database file, etc.
My question is mainly in terms of speed: do a scan of directory which will actually be heavier than a call basis, or equivalent?
Re: Scan a directory or table in database
Yes, but if you stay in reasonable volumes of files, it will do. But by a database you simplify life later if you want to move the files elsewhere, or if you want to put in palc rights management
Re: Scan a directory or table in database
For volume, we will type in 10 or 20 large files up. Especially if many visitors that it worries me.
For moving, I just set the path of files in a file PHP constant and change it when it happens, right?
But, it is true that a scan through the directory, rights management is impossible ...
Re: Scan a directory or table in database
Around twenty files, it is strange. But as said above, it is preferable to use a file management via SQL, it will be much easier now, for instance if you want the future to implement a download counter.
And if you really have a lot of visits and the reduction of a select query to your database would make him the greatest good, directs you to a little cache system
Re: Scan a directory or table in database
If it is to scan your files, you've DirectoryIterator. The DirectoryIterator class provides a simple interface for viewing the contents of filesystem directories.
DirectoryIterator Methods:
- DirectoryIterator::__construct — Constructs a new directory iterator from a path
- DirectoryIterator::current — Return the current DirectoryIterator item.
- DirectoryIterator::getATime — Get last access time of the current DirectoryIterator item
- DirectoryIterator::getBasename — Get base name of current DirectoryIterator item.
- DirectoryIterator::getCTime — Get inode change time of the current DirectoryIterator item
- DirectoryIterator::getFilename — Return file name of current DirectoryIterator item.
- DirectoryIterator::getGroup — Get group for the current DirectoryIterator item
- DirectoryIterator::getInode — Get inode for the current DirectoryIterator item
- DirectoryIterator::getMTime — Get last modification time of current DirectoryIterator item
- DirectoryIterator::getOwner — Get owner of current DirectoryIterator item
- DirectoryIterator::getPath — Get path of current Iterator item without filename
- DirectoryIterator::getPathname — Return path and file name of current DirectoryIterator item
- DirectoryIterator::getPerms — Get the permissions of current DirectoryIterator item
- DirectoryIterator::getSize — Get size of current DirectoryIterator item
- DirectoryIterator::getType — Determine the type of the current DirectoryIterator item
- DirectoryIterator::isDir — Determine if current DirectoryIterator item is a directory
- DirectoryIterator::isDot — Determine if current DirectoryIterator item is '.' or '..'
- DirectoryIterator::isExecutable — Determine if current DirectoryIterator item is executable
- DirectoryIterator::isFile — Determine if current DirectoryIterator item is a regular file
- DirectoryIterator::isLink — Determine if current DirectoryIterator item is a symbolic link
- DirectoryIterator::isReadable — Determine if current DirectoryIterator item can be read
- DirectoryIterator::isWritable — Determine if current DirectoryIterator item can be written to
- DirectoryIterator::key — Return the key for the current DirectoryIterator item
- DirectoryIterator::next — Move forward to next DirectoryIterator item
- DirectoryIterator::rewind — Rewind the DirectoryIterator back to the start
- DirectoryIterator::seek — Seek to a DirectoryIterator item
- DirectoryIterator::__toString — Get file name as a string
- DirectoryIterator::valid — Check whether current DirectoryIterator position is a valid file