php - Symfony 1.4 sfThumbnail not generating thumbnails -


i have upload form, works well, photo being uploaded problem sfthumbnail plugin doesn't seem work. no thumbnail being generated. here's code:

      // /lib/form/uploadform.class.php        public function configure()       {       $this->setwidget('photo', new sfwidgetforminputfileeditable(       array(         'edit_mode' => !$this->isnew(),         'with_delete' => false,         'file_src' => '',          )       ));        $this->widgetschema->setnameformat('image[%s]');        $this->setvalidator('photo', new sfvalidatorfile(         array(         'max_size' => 5000000,         'mime_types' => 'web_images',          'path' => '/images/',         'required' => true,         'validated_file_class' => 'sfmyvalidatedfilecustom'             )        )); 

and here's validator class

    class sfmyvalidatedfilecustom extends sfvalidatedfile{      public function save($file = null, $filemode = 0666, $create = true, $dirmode = 0777)      {       $saved = parent::save($file, $filemode, $create, $dirmode);       $thumbnail = new sfthumbnail(150, 150, true, true, 75, '');       $location = strpos($this->savedname,'/image/');       $filename = substr($this->savedname, $location+15);        // manually point file load sfthumbnail plugin       $uploaddir = sfconfig::get('sf_root_dir').'/image/';       $thumbnail->loadfile($uploaddir.$filename);       $thumbnail->save($uploaddir.'thumb/'.$filename,'image/jpeg');       return $saved;     } 

and actions code:

    public function executeupload(sfwebrequest $request)     {     $this->form = new uploadform();     if ($request->ismethod('post'))     {       $this->form->bind(         $request->getparameter($this->form->getname()),         $request->getfiles($this->form->getname())       );       if ($this->form->isvalid())       {            $this->form->save();            return $this->redirect('photo/success');       }     }      } 

i'm not 100% sure if doing correctly have seen docs , other examples.

you can't use $this->savedname because it's protected value sfvalidatedfile. should use $this->getsavedname() instead.

i don't understand part:

$location = strpos($this->savedname,'/image/'); $filename = substr($this->savedname, $location+15); 

why extract filename, when, finally, re-add /image/ when load loadfile?

any way, made change on class. didn't tested think should work.

class sfmyvalidatedfilecustom extends sfvalidatedfile {   public function save($file = null, $filemode = 0666, $create = true, $dirmode = 0777)    {     $saved    = parent::save($file, $filemode, $create, $dirmode);     $filename = str_replace($this->getpath().directory_separator, '', $saved);      // manually point file load sfthumbnail plugin     $uploaddir = $this->getpath().directory_separator;      $thumbnail = new sfthumbnail(150, 150, true, true, 75, '');     $thumbnail->loadfile($uploaddir.$saved);     $thumbnail->save($uploaddir.'thumb/'.$filename, 'image/jpeg');      return $saved;   } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -