CakePHP – Uploaded File Validation in Models
1st June, 2008 – 3:56 pmAllowing uploaded files from users in PHP is fraught with danger, however by using CakePHP 1.2 and a little bit of Validation magic we can make things a little safer.
First, lets start by creating a simple upload form where the users will be uploading their files
# /app/views/story/create.ctp
echo $form->create(‘Story’, array(‘action’ => ‘create’, ‘type’ => ‘file’));
echo $form->input(‘Story.title’);
echo $form->input(‘Story.contents’);
echo $form->input(‘Artwork.uploaded_image’, array(‘type’ => ‘file’, ‘label’ => ‘Front Artwork’));
echo $form->end(‘Create Story’);
?>
Nothing particularly special here, just to note that we are specifying “type” => “file” in the $form::create method – this makes cake inset the correct ‘enc-type’ value in the generated
3 Trackback(s)