Upload images in Cakephp old framework

20 views Asked by At

I'm using Framework CakePHP 2.5 with Postgresql and I'm trying to upload images and save it.

Table name: Documentos.

view:

<div class="upload-frm">
    <?php echo $this->form->create('Documento',['type'=>'file']);?>
    <?php echo $this->form->input('doc_file',['type'=>'file','class'=>'form-control']);?>               
 </div>

<div class="col-sm-2 col-sm-offset-10">
    <button class="btn btn-yellow btn-block" type="submit"><?php echo __('Guardar'); ?> <i class="fa fa-arrow-circle-right"></i></button>
</div>

controller:

public function index($id)
{  
  if($this->request->is('post'))
   {if(!empty($this->request->data['Documento']['doc_file']))
   { $filename = $this->request->data['Documento']['doc_file'];
    $url=router::url('/',true)."images/$id/".$filename ;
    $uploadpath="images/$id/";
    $uploadfile=$uploadpath.$filename;
    $folderToSaveFiles = WWW_ROOT."images/$id/".$filename  ;

      move_uploaded_file($this->request->data['Documento']['doc_file'],$folderToSaveFiles); //this dont work

     $this->Documento->doc_name=$filename; //all this is fine
    $this->Documento->doc_path=$folderToSaveFiles;
    $this->Documento->id_acti=$id;

    if($this->Documento->save($this->Documento))
        {$this->Session->setFlash(__('it work'), 'success_alert');}
    else {$this->Session->setFlash(__('Dont work'), 'error_alert');}

    }
    else $this->Session->setFlash(__('Dont save'), 'error_alert');
  }    
}

All works, and save all in table Documentos, but i cant upload the file.

In $folderToSaveFiles have this: /var/www/MyApp/webroot/images/10012572/MER.png

I create the folder "images" and "10012572" to test, and dont work. I must be missing something, and cant see it.

0

There are 0 answers