Just a note for myself on how to upload file in Symfony 1.4. This upload feature is a bit different compare to symfony 1.0. I’ve been using Symfony 1.0 for a long time and recently just switch to 1.4 and i found there’s a lot of changes.
To upload file in Symfony 1.4, follow the code below:-
Advertisements
- The code below demonstrate a file upload function that only allow pdf file being uploaded.
// MyForm.class.php $this->validatorSchema['attachment'] = new sfValidatorFile(array( 'required' => false, 'path' => sfConfig::get('sf_upload_dir'), 'mime_types' => array('application/pdf'), ), array('mime_types' => 'The file only accept pdf format.'));
// action.class.php $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName())); if ($form->isValid()) { $file = $form->getValue('attachment_1'); $filename = 'attachment_'.sha1($file->getOriginalName()); $extension = $file->getExtension($file->getOriginalExtension()); $file->save(sfConfig::get('sf_upload_dir') . '/' . date('Ym') . '/' . $filename . $extension); }
Related posts:
Mod Security - Open source Web Application Firewall
How to set print area in Calc - OpenOffice
How to sort drop down - Admin Generator - Symfony 1.4
Cynogenmod: No Vibration when Receiving SMS
How to set out of office auto responder in Zimbra
How to install SVN 1.6 on CentOS 5
Composer: PHP Fatal error: Allowed memory size of ... exhausted...
How to print screen in Asus Zenfone 6
Share this with your friends:-