Yii Framework Forum: [EXTENSION] CFile - Yii Framework Forum

Jump to content

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] CFile Rate Topic: -----

#21 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 22 November 2009 - 06:37 AM

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.yiiframew...xtension/cfile/
0

#22 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 03 December 2009 - 02:13 AM

more useful example


from view:
JHtml::activeFileField(new Node, 'photo');


in controller can be fetch by set:
$photoFile = Yii::app()->file->set('Node[photo]');

0

#23 User is offline   jerry2801 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 504
  • Joined: 18-November 09

Posted 03 December 2009 - 02:35 AM

i sumit a ticket for a bug~

http://code.google.c...ues/detail?id=1
0

#24 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 03 December 2009 - 03:18 AM

View Postjerry2801, on 03 December 2009 - 02:35 AM, said:

i sumit a ticket for a bug~

Yeap, and it's already fixed in SVN.
0

#25 User is offline   light 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 28-September 09
  • Location:Taiwan R.O.C

Posted 06 December 2009 - 01:25 AM

suggest adding a "force_delete" parameter in delete() method.
If file or folder is not writable, will use chmod() before unlink() and rmdir().
0

#26 User is offline   Spyros 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 461
  • Joined: 14-April 09
  • Location:Athens - Greece

Posted 08 December 2009 - 03:24 AM

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
0

#27 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 08 December 2009 - 03:41 AM

View Postlight, on 06 December 2009 - 01:25 AM, said:

suggest adding a "force_delete" parameter in delete() method.

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?

View PostSpyros, on 08 December 2009 - 03:24 AM, said:

I would suggest that set should work with alias too

How do we benefit from that, Spyros?

View PostSpyros, on 08 December 2009 - 03:24 AM, said:

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.
0

#28 User is offline   Spyros 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 461
  • Joined: 14-April 09
  • Location:Athens - Greece

Posted 08 December 2009 - 04:16 AM

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?
0

#29 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 08 December 2009 - 05:29 AM

View PostSpyros, on 08 December 2009 - 03:24 AM, said:

$myExportsDir = Yii::app()->file->set("application.exports")



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.yiiframew...asics.namespace
0

#30 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 08 December 2009 - 05:37 AM

View Postlight, on 06 December 2009 - 01:25 AM, said:

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.
0

#31 User is offline   Spyros 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 461
  • Joined: 14-April 09
  • Location:Athens - Greece

Posted 08 December 2009 - 05:39 AM

View PostMike, on 08 December 2009 - 05:29 AM, said:

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.yiiframew...asics.namespace


You first check if Yii::getPathOfAlias($alias) returns an existing file if not you treat it as url
0

#32 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 08 December 2009 - 05:46 AM

View PostSpyros, on 08 December 2009 - 05:39 AM, said:

You first check if Yii::getPathOfAlias($alias) returns an existing file if not you treat it as url


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()?
0

#33 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 08 December 2009 - 06:25 AM

View PostSpyros, on 08 December 2009 - 04:16 AM, said:

Is there a reason that there's no timeCreated attribute?

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.

View PostMike, on 08 December 2009 - 05:29 AM, said:

They [path aliases] are very useful to make component filepaths configurable and also allow easy access to files inside a module.

Seems to be so. I'll think about possible set() overloading solution.
0

#34 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 09 December 2009 - 01:02 AM

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.yiiframew...xtension/cfile/
0

#35 User is offline   Snover 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 23-August 09

Posted 12 February 2010 - 01:13 AM

It would be great to see some transaction capability, so that file operations can be completed atomically.
0

#36 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 12 February 2010 - 02:57 AM

View PostSnover, on 12 February 2010 - 01:13 AM, said:

It would be great to see some transaction capability, so that file operations can be completed atomically.

What exactly do you mean, any examples?
0

#37 User is offline   transistor 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 05-June 09
  • Location:Mexico

Posted 14 February 2010 - 12:43 AM

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.
0

#38 User is offline   idle sign 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 18-September 09
  • Location:Novosibirsk, Russia

Posted 14 February 2010 - 08:36 AM

View Posttransistor, on 14 February 2010 - 12:43 AM, said:

...
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-e...quickstart.html
A small utility to play with regex: http://weitz.de/regex-coach.
0

#39 User is offline   transistor 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 79
  • Joined: 05-June 09
  • Location:Mexico

Posted 14 February 2010 - 02:17 PM

View Postidle sign, on 14 February 2010 - 08:36 AM, said:

Pattern describing files starting with '20100213014520_' looks like '~/20100213014520_.*/~'. Nb: this should eventually return files regardless of their extension.

Thank you very much! I really appreciate your help.
Developers such as yourself are a big reason why I stay with YIi Framework.
0

#40 User is offline   Snover 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 23-August 09

Posted 15 February 2010 - 02:56 PM

View Postidle sign, on 12 February 2010 - 02:57 AM, said:

What exactly do you mean, any examples?

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
}

0

Share this topic:


  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users