CFile extension offers commonly used functions for file manipulation.


This topic is for your feedback. You’re welcome.

Version 0.2 available

  • new: getContents() and setContents() methods

  • new: create() method

  • new: ‘readable’ & ‘writeable’ properties

  • fix: posix family functions existance check (in getOwner() & getGroup())


That’s great.

I think a download() method would be usefull

Certainly, Spyros, that’s one of the upcoming release @todos.

Version 0.3 available

  • new: setBasename() method (lazy file rename)

  • new: setFilename() method (lazy file rename)

  • new: setExtension() method (lazy file rename)

  • new: download() method

  • chg: copy() & rename() methods improved (destination file name without path is enough for them to perform actions in the current file directory)

  • fix: ‘extension’ key existance check (in pathInfo())


Minor note: Shouldn’t it more correctly be called “send()” instead of “download()”? E.g. what if you want to supply a method to really download a file from somewhere else to the server?

Probably something like "fetch()" would make sense in that case, I believe. What do you think?

Yeah, well: remember you’re on the server side. “download” would be the action on the client side. The server will “send”. But that’s really just nitpicking :)

Version 0.4 is available, introducing directory handling functionality

  • new: ‘isFile’ & ‘isDir’ properties

  • new: rename(), move(), copy(), delete(), getSize() and getContents() methods now are able to deal with directories

  • new: purge() method to empty filesystem object

  • new: createDir() method to create directory

  • new: ‘isEmpty’ property

  • chg: ‘$formatPrecision’ param of getSize() method now changed to ‘$format’ and accepts format pattern for ‘CNumberFormatter’

  • chg: download() method is now alias for primary send() method

  • chg: now ‘readable’ & ‘writeable’ properties are loaded on set() even when in non-greedy mode

  • fix: unnecessary file availability checks when ‘greedy’ option is specified for set() removed


Sendfile is a name for this, and it describes exactly what the application is doing. (EDIT: But would probably be confused with X-SENDFILE which is different).

The "C" prefix is discouraged for extensions as should be used only for core classes. A common practice was to use the "E" prefix

Where do you get it from, I should ask, have I missed something?


Read the qiang message

Also described in the definitive guide: http://www.yiiframework.com/doc/guide/basics.namespace

I see, yes, thank you.

I suppose if this is a discourage as such it should rather be stated in Yii Conventions, not as a Tip or forum message.

But I’ll bear it in mind.

Hmm. Do we have Yii conventions?

I think so :D


Oh, right. I forgot :)

In the dirContents function, the $recursive parameter doesn’t actually do anything. Regardless of whether it’s set to true or false, the function always returns a recursive result.

Also, can I please request a feature? I would like a way to be able to use:


To only display the files/folders in the current folder (ie. non-recursive).


Thank you for the report.

Recursive parameter issue would be fixed in 0.5, and so with that “Yii::app()->file->set(’/files/’)->contents” would work as expected.