Sunday, July 12, 2015

Re: upload images cake 3.0

Look this plugin https://github.com/Xety/Cake3-Upload 



El domingo, 12 de julio de 2015, 6:53:07 (UTC-4:30), Maxwell Ochieng escribió:
I am working with cakePhp 3.0.I am stuck trying to either store the image in the database or image path in the database(either is fine).I have a form that collects information and an image.I am able to get the form to store the image on webroot but I am struggling with storing the same image into a database.My problem is understanding patchEntity() as opposed to what is more popular in cakephp saveFile(). My understanding is this saveFile() would save a selected form filled. I have commented out my two attempts just to illustrate what I have tried so far. Below is my code;


public function add()      {          $car = $this->Cars->newEntity();          if ($this->request->is('post')) {           $car = $this->Cars->patchEntity($car, $this->request->data);          //debug($this->request->data);die();           $now = time();           $dir = WWW_ROOT.'files'.DS.'uploads';           $extension = strtolower(pathinfo($this->request->data['user_pic_path']['name'],PATHINFO_EXTENSION));            if(!empty($this->request->data['user_pic_path']['tmp_name'])&&            in_array($extension,array('jpg','jpeg','png','pdf'))            ){                move_uploaded_file($this->request->data['user_pic_path']['tmp_name'],                $dir.DS . '-' . $extension                );                $this->request->data = array();                //$this->Cars->save($this->request->data);                 //$this-Cars->PatchEntity($car,$this->request->data['user_pic_path']['tmp_name']);              }                if ($this->Cars->save($car)) {                  $this->Flash->success(__('The car has been saved & new file uploaded'));                  return $this->redirect(['action' => 'index']);              } else {                  $this->Flash->error(__('The car could not be saved. Please, try again.'));              }          }          $this->set(compact('car'));          $this->set('_serialize', ['car']);      }

--
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/d/optout.

No comments: