idle
(Idlesign)
November 22, 2009, 11:37am
21
Version 0.5 is available, introducing uploaded files handling (see CFile Documentation for usage example).
new: Uploaded files support (through CUploadedFile Yii class)
new: ‘isUploaded’ property
chg: getContents() method now has ‘recursive’ parameter for directories
fix: always recursive dirContents() method behaviour changed to appropriate
http://www.yiiframework.com/extension/cfile/
jerry2801
(Jerry2801)
December 3, 2009, 7:13am
22
[size="7"]more useful example[/size]
from view:
JHtml::activeFileField(new Node, 'photo');
in controller can be fetch by set:
$photoFile = Yii::app()->file->set('Node[photo]');
jerry2801
(Jerry2801)
December 3, 2009, 7:35am
23
idle
(Idlesign)
December 3, 2009, 8:18am
24
Yeap, and it’s already fixed in SVN.
light
(Admin)
December 6, 2009, 6:25am
25
suggest adding a "force_delete" parameter in delete() method.
If file or folder is not writable, will use chmod() before unlink() and rmdir().
Spyros
(Spyros)
December 8, 2009, 8:24am
26
I would suggest that set should work with alias too
eg
$myExportsDir = Yii::app()->file->set("application.exports")
Also
$file->getContents($filter)
where filter can be a string ".jpg" or an array(".jpg",".gif",".png")
could be useful
idle
(Idlesign)
December 8, 2009, 8:41am
27
Interesting option though arguable. Mainly from the security point of view. I think potential risk to remove everything under / is spooky. Could you tell me whether your http server uses root priviledges?
How do we benefit from that, Spyros?
light:
Also
$file->getContents($filter)
where filter can be a string ".jpg" or an array(".jpg",".gif",".png")
could be useful
That’s the sugar I was thinking to introduce in 0.6 Thank you for your interest.
Spyros
(Spyros)
December 8, 2009, 9:16am
28
It’s easier to write application.exports than Yii::app()->basePath.DIRECTORY_SEPARATOR.“exports”
Also there’s the webroot alias that points outside the protected folder
Another thing I was wondering. Is there a reason that there’s no timeCreated attribute?
mikl
(Mike)
December 8, 2009, 10:29am
29
But how would you know, that it’s a path alias? Maybe use a second parameter to indicate that it’s an alias (defaulting to false)? Apart from that, i also think path aliases should be supported. They are very useful to make component filepaths configurable and also allow easy access to files inside a module.
It’s easy to implement: http://www.yiiframework.com/doc/guide/basics.namespace
mikl
(Mike)
December 8, 2009, 10:37am
30
light:
suggest adding a "force_delete" parameter in delete() method.
If file or folder is not writable, will use chmod() before unlink() and rmdir().
If you don’t have permission to delete a file, you’re also not permitted to chmod the file. So that wouldn’t be very reliable anyway.
Spyros
(Spyros)
December 8, 2009, 10:39am
31
But how would you know, that it’s a path alias? Maybe use a second parameter to indicate that it’s an alias (defaulting to false)? Apart from that, i also think path aliases should be supported. They are very useful to make component filepaths configurable and also allow easy access to files inside a module.
It’s easy to implement: http://www.yiiframework.com/doc/guide/basics.namespace
You first check if Yii::getPathOfAlias($alias) returns an existing file if not you treat it as url
mikl
(Mike)
December 8, 2009, 10:46am
32
Hmm, but that’s “expensive”, don’t you think so? I see, that set() already has a second parameter. So how about simply separating it into a setFromAlias() ?
idle
(Idlesign)
December 8, 2009, 11:25am
33
File creation time you may be accustomed to have in Windows is a very ambiguous thing, essentially there is no way to get that timestamp on Unix, as it is considered useless. I don’t know whether we need filectime() ambiguousness here in CFile.
Seems to be so. I’ll think about possible set() overloading solution.
idle
(Idlesign)
December 9, 2009, 6:02am
34
Version 0.6 is available, introducing Yii aliases handling and directory contents filters (see CFile Documentation for usage examples).
new: ‘set()’ method now supports Yii path aliases (proposed by Spyros)
chg: ‘getContents()’ method now has ‘filter’ parameter to return filtered directory contents (regexp supported)
fix: undefined ‘uploaded’ variable in ‘set()’ method (spotted by jerry2801)
http://www.yiiframework.com/extension/cfile/
snover
(Yiiframework Com)
February 12, 2010, 6:13am
35
It would be great to see some transaction capability, so that file operations can be completed atomically.
idle
(Idlesign)
February 12, 2010, 7:57am
36
What exactly do you mean, any examples?
transistor
(Jlsistemas)
February 14, 2010, 5:43am
37
Hello.
I’m starting to use your extension, it is very helpful, thank you.
I have a set of image files that start with the same prefix and I want to apply a flter to avoid having to process all the files.
Array
(
[0] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/.DS_Store
[1] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213014520_68949.jpg
[2] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213014520_74450.jpg
[3] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213014520_87550.jpg
[4] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213015037_33518.jpg
[5] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213015037_41118.jpg
[6] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213015037_59718.jpg
[7] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213015037_70319.jpg
[8] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213024408_14856.jpg
[9] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213024408_86055.jpg
[10] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213024408_95855.jpg
[11] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213030709_91220.jpg
[12] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213030709_96520.jpg
[13] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213030709_99220.jpg
[14] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213230123_84355.jpg
[15] => /Applications/xampp/xamppfiles/htdocs/vmc_yii/protected/tmp/20100213230536_42602.jpg
)
And I want to filter those that start with: 20100213014520_
The extension could be JPG, GIF or PNG.
I am not good with regex, could you please help me how to use a regex to filter these files?
Thank you.
idle
(Idlesign)
February 14, 2010, 1:36pm
38
transistor:
…
And I want to filter those that start with: 20100213014520_
The extension could be JPG, GIF or PNG.
I am not good with regex, could you please help me how to use a regex to filter these files?
Thank you.
Pattern describing files starting with ‘20100213014520_’ looks like ‘~/20100213014520_.*/~’. Nb: this should eventually return files regardless of their extension.
On regular expressions: http://www.regular-expressions.info/quickstart.html
A small utility to play with regex: http://weitz.de/regex-coach .
transistor
(Jlsistemas)
February 14, 2010, 7:17pm
39
Thank you very much! I really appreciate your help.
Developers such as yourself are a big reason why I stay with YIi Framework.
snover
(Yiiframework Com)
February 15, 2010, 7:56pm
40
I mean the same as a database transaction.
<?php
try
{
$file = Yii::app()->file;
$transaction = $file->beginTransaction();
$file->set('file1');
$file->rename('other/file1');
$file->set('file2');
$file->delete();
$file->set('file3');
$file->rename('other/file3'); // will fail for some reason! throw CException
$transaction->commit(); // commits file operations
}
catch(Exception $e)
{
$transaction->rollback(); // undoes file operations
}