Yii Framework Forum: Best Way To Add Filesystem Storage To A Model - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Best Way To Add Filesystem Storage To A Model Rate Topic: -----

#1 User is offline   Arno S 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 16-October 12
  • Location:Zwolle, The Netherlands

Posted 28 June 2013 - 03:31 AM

I need to store uploaded files. For this I use a database table which holds the meta data for the file and I store the file on the filesystem, I add the path to a database row.

What is the best way to integrate this into a model?

I'd like the ActiveRecord model to handle the storing and retrieving automatically as if the upload was stored in the database itself.
What is the best way to implement this, are there perhaps applicable examples or extensions out there?

Thx
0

#2 User is offline   Arno S 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 16-October 12
  • Location:Zwolle, The Netherlands

Posted 30 June 2013 - 02:47 PM

I was thinking of overriding the __set and __get and add a property to handle the actual file and add an beforesave to handle the storage to the filesystem.

Can anyone confirm if that is the best way to go or are there alternatives?
0

#3 User is offline   Tsunami 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 150
  • Joined: 16-February 12

Posted 30 June 2013 - 03:49 PM

Use CUploadedFile.
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,909
  • Joined: 16-February 11
  • Location:Japan

Posted 30 June 2013 - 08:24 PM

Hi Arno S,

Probably you have a specific use case in your mind ... like 1) user uploads an image file 2) allows the user to edit it 3) updates the file ... or something similar.

As far as I know, there's no official support for it in CActiveRecord.

There's a lot of extensions that try to handle image files ... I haven't tried any of them so far, but I would want to try this one first. http://www.yiiframew.../extension/img/
0

#5 User is offline   Arno S 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 16-October 12
  • Location:Zwolle, The Netherlands

Posted 01 July 2013 - 03:33 AM

Thanks for the responses.

My problem isn't related to handling the uploaded file, but more that I want to influence how CActiveRecord does the storage for me as Softark understood correctly. It's good to hear that there is no real support for what I want, I at least understood things right how everything works ;)

The img extension is a nice one to look at since it does in some way do what I want. I'll look at that code and use that for inspiration.
0

Share this topic:


Page 1 of 1
  • 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