Monday, February 17, 2014

Re: File Upload Err..

I usually upload the file using the following method :
In the file controlller PostsController :
        public function add(){
            $this->layout = false;
            if($this->request->is('post')){
                $date = getdate();
                $name_img = 'img-'.$date['hours'].$date['minutes'].$date['seconds'].'-'.$date['mday'].
                $date['mon'].$date['year'];
                $img_upload = $this->Uploader->upload('image', array('overwrite' =>true,'name' =>$name_img));
                $this->request->data['Post']['image'] = $img_upload['path'];
                $this->Post->create();
                $this->Post->save($this->request->data);
                //return $this->redirect(array('action'=>'index'));
            }


        }
file view add.ctp:
<?php
     echo $this->Form->create('Post',array('type' => 'file'));
     echo $this->Form->input('Post.image',array('type'=>'file','label'=>'Image'));
     echo $this->Form->end(' Add ');
?>

Database exist table posts : id, image(varchar(255))...
This will be somewhat helpful for you. Also you need to Uploader Plugin installed correctly.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: