[Solved] how to upload image in cakephp2.5+ and store it in webroot folder [closed]


Use following

echo $this->Form->create('Tour',array('autocomplete' => 'off','enctype'=>'multipart/form-data'));

Allows image/video data to be processed.

Inside controller

if ($this->request->is('post')) {

    if(is_uploaded_file($this->request->data['Tour']['varbigimg']['tmp_name']))
    {
        $fileNameFull = $this->request->data['Tour']['varbigimg']['name'];

        $oldFile="../../app/webroot/img/".$fileNameFull; 

        move_uploaded_file(
          $this->request->data['Tour']['varbigimg']['tmp_name'],
          $oldFile
        );

        $this->Tour->create();
        $this->request->data['Tour']['varbigimg'] = $fileNameFull;

//HERE you need to specify same for thum

        $this->request->data['Tour']['varthumimg'] = $fileNameFull;

////HERE you need to specify same for thumbfield

        if ($this->Tour->save($this->request->data)) {
            $this->Session->setFlash(__('Your possstt has been saved.'));
            return $this->redirect(array('controller'=>'admin','action' => 'tour'));
        }

    }
}
$this->Session->setFlash(__('Unable to add your schedule.'));

//Update

//Specify input type in your code explicitely here.

echo $this->Form->input('vartitle',array('type'=>'text','class' => 'form-control','label' => 'Tour Title'));

17

solved how to upload image in cakephp2.5+ and store it in webroot folder [closed]