Can You put one more function into todo list - recursice dirs creation.
When you give for function stable path to images and another path with parameters to image.
Example:
C:/www/yii_project/images/ this is stable path and know I gave dynamic path - "category_id/sub_category_id/item_id/" so the function must check if there exists all three directories and if not, create them.
So I have created new item and uploaded file for example test.jpg for that item. Now I wannt to put him into directory somewhere C:/www/yii_project/images/item_category/item_sub_category/item_sub_sub_category/item_id/test.jpg
Now I have just read that I can check if this C:/www/yii_project/images/item_category/item_sub_category/item_sub_sub_category/item_id/ directory exists and if not with mkdir recursively create it.
Yeap, you can use copy method, it should handle directory creation for you:
// Suppose you're using Item model with 'file' attribute for upload
$uploaded = Yii::app()->file->set('Item[file]');
// Let's copy newly uploaded file into your directory with file original name.
$newfile = $uploaded->copy('C:/www/yii_project/images/item_category/item_sub_category/item_sub_sub_category/item_id/'.$uploaded->basename);
Hello! Good extension. Unfortunatly I have a problem with delete() method. In project I do, we use SVN, so it creates in every folder hidden “.svn” folder. If I try to delete folder using delete() method these “.svn” folders inside the folder I try to delete are still there so at last folder is impossible to delete ('cause it is not empty). I use windows. Is it a bug or my mistake? Thanks.
Found php5 function that works (deletes .svn folders):
I want to extend your class with it. Instead of method argument (tmp_path) I wanna use $this->_realpath in deleteExtended(), so I can access it via object. So here goes the second question.
Is it possible to create extended class from your cFile class? I need all your functionality from original class but only one new deleteExtended() method. I tried, didn’t worked out. Maybe you can help? Thanks.
I wanted to do my own Component, based on your extension, because I need more advanced methods.
So I did "class CMyFile extends CFile". And then I run into problems.
I tried creating a new CMyFile instance and tried something like “file = CMyFile::set(‘files/test3.txt’)” and ended up with Call to undefined method.
Then I created a __construct method in CMyFile with “$this -> set(‘files/test3.txt’)”. Also tried parent::set and self::set. I always get returned an instance, but it’s never the CMyFile, only a new CFile.
Try to turn on DEBUG mode and see are there any ‘Unable to delete filesystem object’ messages in the log. If so that’s permissions problem. CFile doesn’t try to change permissions on it’s own, instead you should do that explicitly.
I tried to reproduce delete fail you described on my Linux box when permissions are right, but with no success.
For answer on your second question see my next comment to edmund.
I did a class CMyFile of my which has an $_i property.
In the CMyFile::__construct($path) I just do $this -> _i = CMyFile::set($path).
I need a more advanced copy, so I made a new method called CMyFile::copy. I do the stuff that needs to be done before copying and then just call the CFile method: $this -> _i -> copy().
Works for me, although no proper class extension, just a workaround.
And one more thing for this workaround and other class derivatives: inspite of C prefix (as in CFile for historical reason) Yii docs asks for E class prefix (e.g. EMyFile) for extensions.
When downloading file by calling download() method, the download is always nothing (zero file size) even though file exists and there are content in the file. After some debugs and walk through investigations, I found that the problem lies in getSize() method. When the file size hasn’t been set and false is passed as parameter, the value returned is incorrect.
The problem is fixed by adding a line to getSize() method, just before close bracket at line 635 of source code:
...
if (!isset($this->_size)){
.....
size = $this->_size; // <-- add this
}
....