davidyell / CakePHP-Proffer

An upload plugin for CakePHP 3
MIT License
117 stars 63 forks source link

Possibility to save uploads in one database table? #260

Closed inbound-be closed 6 years ago

inbound-be commented 6 years ago

Hi,

This is a pre-install question. I'm developing a new application and am looking for a good plugin that can handle file & image uploads (with image resizing).

At first glance, the behaviour of this plugin is you have to create 2 new fields (filename en filedir) for each file you'd like to save? I'd like to have one single "uploads" table for file uploads for each possible model. A bit like the Core Translate behaviour works actually. In this "uploads" table I would like each row to contain a "model_name", "model_key", "file_dir", "file_name" for example. So the information of all my uploads can be stored in one single database table instead of dispersed over the different tables that have uploads.

Is this in a way possible or not? Thanks

davidyell commented 6 years ago

Yes, this is possible. You just attach the behaviour to the association. So if Posts hasMany Uploads you would attach the behaviour in the Uploads table class.

I have done this in my example application. https://github.com/davidyell/CakePHP3-Proffer-Example/blob/master/src/Model/Table/UploadsTable.php#L42