This extension offers commonly used functions for filesystem objects (files and directories) manipulation. Can be used separately from Yii.
Please use CFile project repository at GitHub for your reports.
Documentation is available at CFile repository.
CFile exposes:
Properties ¶
- exists
- isdir
- isfile
- isempty
- isuploaded
- readable
- writeable
- realpath
- basename (setter available)
- filename (setter available)
- dirname
- extension (setter available)
- mimeType
- timeModified
- size
- owner (setter available)
- group (setter available)
- permissions (setter available)
Methods ¶
- Create
- CreateDir
- Purge
- Contents (get; set for files, append possible; contents filters for directories)
- Copy
- Rename/Move
- Send/Download ('x-sendfile' header support)
- Delete
Great
Great extension!
great
Really usefull and handy. Thanks a lot.
Must have extension!
Really useful.
That's Great
Very usefull, saved me a lot of time :)
Re: is this free?
@jackiesun: As free as in beer, why would you think it is not? :)
is this free?
is this free?
is useful!
Thank you!
Error mb_substr_count() [function.mb-substr-count]: Unknown encoding "63"
Hello. Trying this....
$cfileDir = Yii::app()->file->set('ext.file'); print_r($cfileDir->getContents(false,'php'));
I get follow errors:
Description mb_substr_count() [<a href='function.mb-substr-count'>function.mb-substr-count</a>]: Unknown encoding "63" Source File C:\EasyPHP 2.0b1\www\yii-miniweb\protected\extensions\file\CFile.php(864) 00852: */ 00853: private function filterPassed($str, $filter) 00854: { 00855: $passed = false; 00856: 00857: if ($filter!==null) 00858: { 00859: foreach ($filter as $rule) 00860: { 00861: if ($rule[0]!='/') 00862: { 00863: $rule = '.'.$rule; 00864: $passed = (bool)substr_count($str, $rule, strlen($str)-strlen($rule)); 00865: } 00866: else 00867: $passed = (bool)preg_match($rule, $str); 00868: 00869: if ($passed) 00870: break; 00871: } 00872: } 00873: else 00874: $passed = true; 00875: 00876: return $passed;
Really good extension
Thank you for the work, that' really a good extension.
Great!
Sir, you saved me a lot of time with this stuff.
Gracias!
please disable one feature
Hi idle,
I have one suggestion. What do you think about disabling file size formatting while $greedy parameter of "set" function is "true" ? Now autoloaded file data contains formated size by default ...
Regards,
gawronzo
detecting xsendfile
Documentation (above) says:
If CFile::download() second parameter ('serverHandled') is set to True...
Why not detect it within the method?
[code]
$xsendfile=(in_array('mod_xsendfile',apache_get_modules()))?true:false;
[/code]
resubmitting...sorry
Sorry, that was supposed to look like this
$xsendfile=(in_array('mod_xsendfile',apache_get_modules()))?true:false;
Problem with permissions
I couldn't get this extension to create a directory with the correct permissions on my production server, not 100% sure why. Safe_mode is off.
I tried this
$imageTopFolder->createDir('0754',$path.$this->eventImageTemp);
But no joy!
After much hair pulling I did this based on info from php.net and from looking at the Yii assets manager code.
$oldumask = umask(0); @mkdir($path.$this->eventImageTemp, 0754); // or even 01777 so you get the sticky bit set @umask($oldumask);
I don't know if others have had this problem.
Thumbs up!
Thank you!
Good Extension
But I have an issue on the Linux server (on Win localhost works), maybe it's the PHP version:
Unexpected T_PAAMAYIM_NEKUDOTAYIM
CFile.php lines 215 and 216.
Now working with $this instead of ::
oups
Same here : NEKUDOTAYIM etc ... error on win platform - php 5.2.11
ftp
good extension!
It would be cool to add FTP support as all used php functions support it now.
it copy very slow
Hi when i use cfile it takes time to copy and sometime error shows Maximum execution time of 30 seconds, how can i speed up copy? also it needs to refresh if loading is stop to continue the copy. and how can i put an ajax their or i want that something loading .gif is show while it still copying????
on the other hand, it cool extension.....
Base class
CFile
is currently based onCApplicationComponent
. Consider, if you could base it onCFileHelper
. This way users of your extension can have access to functions offered by both file-related classes.@Vitalets
Support for FTP and other protocols is native in PHP at most file-operating functions. See "Supported Protocols and Wrappers". This means, that you should be able to simply use any of supported protocols (for example
file://
) when specifing file name viaCFile->filename
.setContents Error!
Hi,
First of all, thanks for this class...
I've found an error in setContents method:
If I set autocreate to true, it never creates the file because it validates if is a file before and that will never happen.
Sorry for my english!
Thanks again!
Use
readfile
instead ofecho $contents
Consider changing CFile to use
readfile
instead ofecho $contents
, which is more secure in case of binary files. I found a notice like that somewhere in PHP's readfile() function description and changed your extension manually to fit this.Mr
Hello!
I am a little bit new with Yii and I don't know how can to create a new directory and how to view its contents.
May somebody help me please!
Thank you very much!
@Kreshnik Arapi
Take a look at comment #4593 below, by got 2 doodle, made at 2011/07/23 12:51pm. You'll find some examples on
CFile::createDir
there.Downloading large files with CFile extension
CFile
offers you support ofmod-xsendfile
plugin, if you're using Apache server and have it properly configured to use it. If not, it falls back to old, badreadfile
. This core PHP function will fail on files even as small as 100-200 MB, even if you have quite very high maximum memory limit set.What is the saddest, you may not even notice, that your script (that uses
CFile
, that usesreadfile
) fails, because -- due to some stupidity of PHP creators -- on certain server configurations, your file will be downloaded in this case, but instead of real content, it will contains a PHP generated HTML code with "exhausted memory" error message.To avoid this problem, if you can't use
mod-xsendfile
you have to manually extendCFile
to use file chunking. Here you have my answer on Stack Overflow. Use provided code in place, whereCFile
extension callsreadfile
function.delete file before send it
Hi I've a function for send file to browser, but if I check $file-exists() and delete it before, don't send any file !! Why ?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.