I want to upload image using cakephp and i am able to save file name in database but my file file is not uploading in specified path ihave tried the below code but my problem has not solved
This is my 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 to create one in webroot
$uploadFolder = "upload";
//full path to upload folder
$uploadPath = WWW_ROOT . $uploadFolder;
$imageName = $image['name'];
if($image['size'] > 2097152){
$errors[]='File size must be less than 2 MB';
}
//check if image type fits one of allowed types
if(empty($errors)==true){
if(is_dir($uploadPath)==false){
mkdir("$uploadPath", 0700); // Create directory if it does not exist
}
if(is_dir("$uploadPath/".$imageName)==false){
move_uploaded_file($image['tmp_name'],"$uploadPath/".$imageName);
}else{ // rename the file if another one 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 a post ');
}
This is my view
echo $this->Form->input('upload image',array( 'type' => 'file' , 'style' => 'margin-left:9%;'));