Setup
1. Click on -> CFILE and download the folder.
2. Unzip and copy the folder in to protected/extensions path
3. Rename the folder to file
4. Add the following code into protected/config/main.php
'components'=>array(
'file' => array(
'class' => 'application.extensions.file.CFile',
),
),
How to Use
// yourfile
$yourfile = 'sample.txt';
// Call extension into $cfile variable
$cfile = Yii::app()->file;
// Check file exist
$cfile->set($yourfile)->exists;
// Create file
$cfile->set($yourfile)->create();
// Append Content
$cfile->set($yourfile)->setContents('treat me a coffee for this tutorial!');
// Get Content from file
$cfile->set($yourfile)->getContents();
// Delete File
$cfile->set($yourfile)->delete();
Others available method as follow:
- Create
- CreateDir
- Purge
- Contents (get; set for files, append possible; contents filters for directories)
- Copy
- Rename/Move
- Send/Download ('x-sendfile' header support)
- Delete
- 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)
No comments:
Post a Comment