I am storing some files in the MySQL database as BLOB. I would like to have a download possibility for the BLOB files in my view. All informations are accessible, but how can I download the file from the database according to the MVC model?
MVC is a pattern, not a law. So you are always free to code it your way. But according to current standard you would avoid a View, because there is nothing to display. Just a controller which is getting the data from the Model and returning it as response.
In most cases i would write a general Controller for handling files and inherit from it.
Basically you can do it with a controller and a model.
The controller will be called like:
index.php?option=com_example&task=getFile&fileName=example.png&format=rawwhere the controller will call a method from the model and will make sure it provides the right header so that the browser can display / download the file.
The model can have a simple
getFile($fileName)method and will return the result of the query.