How to upload file in cakephp -


i want upload image using cakephp , able save file name in database file file not uploading in specified path ihave tried below code problem has not solved

this controller

function editprofile ($id = null){                 if(empty($this->data)){                     $this->data=$this->signup->read(null, $id);                 }                 else{               $image = $this->data['signup']['upload image'];                 //allowed image types                 $imagetypes = array("image/gif", "image/jpeg", "image/png");                 //upload folder - make sure create 1 in webroot                 $uploadfolder = "upload";                 //full path upload folder                 $uploadpath = www_root . $uploadfolder;  $imagename = $image['name'];  if($image['size'] > 2097152){             $errors[]='file size must less 2 mb';         }                    //check if image type fits 1 of allowed types                 if(empty($errors)==true){             if(is_dir($uploadpath)==false){                 mkdir("$uploadpath", 0700);     // create directory if not exist             }             if(is_dir("$uploadpath/".$imagename)==false){                 move_uploaded_file($image['tmp_name'],"$uploadpath/".$imagename);             }else{                                  // rename file if 1 exist                 $new_dir="$uploadpath/".$imagename.time();                  rename($image['tmp_name'],$new_dir) ;                           }          }                      if ($this->signup->save($this->data)) {                         $this->session->setflash($imagename);                         return $this->redirect(array('action' => 'editprofile',$id));                     }                   }                 $this->set('languageoptions', array('opt1' => 'choose occupuation', 'opt2' => 'student', 'opt3' => 'employee'));     debug($this->signup->validationerrors);     debug($this->signup->getdatasource()->getlog(false, false));                  //$this->set('title_for_layout', 'add post ');         } 

this view

echo $this->form->input('upload image',array( 'type' => 'file' , 'style' => 'margin-left:9%;')); 

i've run issue several times myself, , problem caused detail keep forgetting: setting right enctype form. based on code above, can't see obvious mistakes, i'm not able see if enctype set multipart/form-data or not. try when create form in view (note 'type' => 'file'):

echo $this->form->create('formname', array('type' => 'file')); 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -