Uploading Multiple Files in CakePHP


There are many plugins available on the internet for attaching files.

This custom made script will give you idea on how to attach multiple files. In this script, we have a model Attachment and Document. Attachment model saves all information of the file while Document is just an add-on if you have model related to your attachment. If none, then just omit it and it should still run well.

First in the Attachments view “index.ctp” we will create a form that will look for files.

Next in our AttachmentsController we need to add the File and Folder classes. You might as well create the index function as well.

The purpose of the parameter is that I want to get additional information in my Document model such as ID and save it to my Attachment’s table so that I can identify which attachments belongs to a certain document. Inside the index function add the following code.

Just follow the comments to further understand in.

That’s it, if you follow along, you should be able to run it well.

For downloading of the uploaded files click here: Downloading Files in CakePHP

Sharing is caring!