I need a list of all the files (and associated file sizes) on an FTP server. I can get a list of files using CodeIgniter’s FTP class, but no idea how to get the file size. How do I get the file sizes? Thanks.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Since CI is still PHP 4 compatible you probably can do it quick and dirty as follows :
In $files you should get one line per file, containing file permissions, owner/group, filesize and filename. You will have to parse this to display them separately.
DISCLAIMER : Just copy/pasted the connection info from the CI manual, added the last line based on the CI source code, YMMV :p.
I know nothing about CodeIgniter's FTP class, but what about this?
http://www.php.net/manual/en/function.ftp-rawlist.php
I assume that the FTP class' list_files() method doesn't provide this info. Is that correct?
Note that there is a chanche that the FTP server has ceratin functions disabled, or it won't let you call then(for example the filesize() function). Also, the standard filesize() http://php.net/manual/en/function.filesize.php functionshould work over ftp
Its relatively simple to extend the CI FTP class:
Essentially just make get_ftp_size() a wrapper for:
http://php.net/manual/en/function.ftp-size.php
I hope this helps (if you are stuck just skim through the ftp.php file of your install; you should soon find your way)
Edit
As wimvds rightly suggest's ftp_rawlist() might be the more preferable/easier option, i may even go so far as to suggest altering list_files() to use ftp_rawlist().
Using the file helper
After hard work, this code works great!!!! and I want to share with the community (by MundialSYS)
Good code! Fernando