Best Way To Add Filesystem Storage To A Model

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

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?

Use CUploadedFile.

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.yiiframework.com/extension/img/

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.