[symfony-users] Re: Problem with File Upload
Thanks Dennis. Now works fine, but I have another problem: Validation failed in class People 1 field had validation error: * 1 validator failed on image (type) why? thanks -- You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-us...@googlegroups.com. To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en.
[symfony-users] Re: problem with file upload
Thx YOU xD !! On 8 Mar, 21:57, Marijn wrote: > Well, you chose to have maximum file size of 1000 bytes... Try the > following > > new sfValidatorFile(array('required' => true, 'mime_types' => array > ('image/jpeg', 'image/jpg', 'image/png', 'image/gif'), 'max_size' => > 2097152), array('max_size' => 'File size of 2MB exceeded', > 'mime_types' => 'You are only allowed to upload JPG, PNG or GIF > files.')); > > On Mar 8, 8:07 pm, dziobacz wrote: > > > I would like to make very safe upload file: .gif, .jpg and .png but I > > am new in symfony. Could you tell me is my code safe ? And why I have > > non stop communicate 'Too big size' - it is my own communicate (see > > below)?? Sry for some polish names in my code below :) > > > class UploadForm extends sfForm > > { > > public function configure() > > { > > $this->setWidgets(array( > > 'file' => new sfWidgetFormInputFile(), > > )); > > > $this->widgetSchema->setNameFormat('minifile[%s]'); > > > $this->setValidators(array( > > 'file' => new sfValidatorFile(array( > > 'required' => true, > > 'mime_types' => 'image/jpeg, image/png, image/gif', > > 'max_size' => '1000', > > ), > > array( > > 'max_size' => 'Too big size', > > 'mime_types' => 'Only .jpeg, .png or .gif', > > )), > > )); > > > } > > > } > > > public function executeUpload(sfWebRequest $request) > > { > > $this->form = new UploadForm(); > > > if ($request->isMethod('post')) > > { > > $this->form->bind($request->getParameter('minifile'), > > $request->getFiles('minifile')); > > > if ($this->form->isValid()) > > { > > > $file = $this->form->getValue('file'); > > > $filename = $this->getUser()->getGuardUser()->getId(); > > $extension = > > $file->getExtension($file->getOriginalExtension()); > > $file->save(sfConfig::get('sf_upload_dir').'/'.$filename. > > $extension); > > > $id = $this->getUser()->getGuardUser()->getId(); > > $nazwa = $filename.$extension; > > $this->profill = > > Doctrine::getTable('SfGuardUserProfile')->setUploadPhoto($id, $name); > > > } > > } > > } > > > public function setUploadPhoto($id, $name) > > { > > $q = Doctrine_Query::create() > > ->update('SfGuardUserProfile sgup') > > ->set('sgup.photo', '?', $name) > > ->where('sgup.user_id = ?', $id); > > > return $q->execute(); > > } > > --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---
[symfony-users] Re: problem with file upload
Well, you chose to have maximum file size of 1000 bytes... Try the following new sfValidatorFile(array('required' => true, 'mime_types' => array ('image/jpeg', 'image/jpg', 'image/png', 'image/gif'), 'max_size' => 2097152), array('max_size' => 'File size of 2MB exceeded', 'mime_types' => 'You are only allowed to upload JPG, PNG or GIF files.')); On Mar 8, 8:07 pm, dziobacz wrote: > I would like to make very safe upload file: .gif, .jpg and .png but I > am new in symfony. Could you tell me is my code safe ? And why I have > non stop communicate 'Too big size' - it is my own communicate (see > below)?? Sry for some polish names in my code below :) > > class UploadForm extends sfForm > { > public function configure() > { > $this->setWidgets(array( > 'file' => new sfWidgetFormInputFile(), > )); > > $this->widgetSchema->setNameFormat('minifile[%s]'); > > $this->setValidators(array( > 'file' => new sfValidatorFile(array( > 'required' => true, > 'mime_types' => 'image/jpeg, image/png, image/gif', > 'max_size' => '1000', > ), > array( > 'max_size' => 'Too big size', > 'mime_types' => 'Only .jpeg, .png or .gif', > )), > )); > > } > > } > > public function executeUpload(sfWebRequest $request) > { > $this->form = new UploadForm(); > > if ($request->isMethod('post')) > { > $this->form->bind($request->getParameter('minifile'), > $request->getFiles('minifile')); > > if ($this->form->isValid()) > { > > $file = $this->form->getValue('file'); > > $filename = $this->getUser()->getGuardUser()->getId(); > $extension = > $file->getExtension($file->getOriginalExtension()); > $file->save(sfConfig::get('sf_upload_dir').'/'.$filename. > $extension); > > $id = $this->getUser()->getGuardUser()->getId(); > $nazwa = $filename.$extension; > $this->profill = > Doctrine::getTable('SfGuardUserProfile')->setUploadPhoto($id, $name); > > } > } > } > > public function setUploadPhoto($id, $name) > { > $q = Doctrine_Query::create() > ->update('SfGuardUserProfile sgup') > ->set('sgup.photo', '?', $name) > ->where('sgup.user_id = ?', $id); > > return $q->execute(); > } --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~--~~~~--~~--~--~---