O'Reilly logo

CakePHP 2 Application Cookbook by Jorge González, James Watts

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Uploading a file

Creating forms and submitting data is usually easy until you have to deal with file uploads. Luckily, the framework doesn't tread on any toes here and lets you build the process as your application demands.

In this recipe, we'll look at a file upload scenario and build a process that is clean and helps maintain the separation of concerns in our application.

Getting ready

To begin with, we'll need to create a table to track our file uploads. For this, create a table named uploads with the following SQL statement:

CREATE TABLE uploads (
  id INT(11) NOT NULL AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  size INT(4) UNSIGNED NOT NULL,
  mime VARCHAR(50) NOT NULL,
  path TEXT NOT NULL,
  created DATETIME,
  modified DATETIME,
  PRIMARY KEY(id)
);

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required