我正在使用cakephp Qimage组件进行图片上传。
public function img_uploads(){
$data['file']= $this->request->data['Basicprofile']['photo'];
$data['path']= WWW_ROOT . 'img/uploads/teachers/';
unset($this->request->data['Basicprofile']['photo']);
$this->request->data['Basicprofile']['photo']=$this->Qimage->copy($data);
}
// Qimage复制功能
public function copy($data){
// Verify file and path
if (!isset($data['file']) || !isset($data['path']) || !is_array($data['file'])){
$this->errors[] = 'Name or path not found!';
return false;
}
if (!is_writable($data['path'])){
$this->errors[] = 'Destination path is not writable!';
return false;
}
if (!$this->_verifyMime($data['file']['name'])){
$this->errors[] = 'The file must be an jpg, gif or png image!';
return false;
}
// Generate filename and move file to destination path
$filename_array = explode('.', $data['file']['name']);
$ext = end($filename_array);
$ext = strtolower($ext);
$name = uniqid() . date('dmYHis') . '.' . $ext;
$complete_path = $data['path'] . DIRECTORY_SEPARATOR . $name;
if (!move_uploaded_file($data['file']['tmp_name'], $data['path'] . $name)){
$this->errors[] = 'Error while upload the image!';
return false;
}
// Return image filename
return $name;
}
问题是路径不可写。我给了777上传文件夹的权限。静止图像无法上传。有什么建议吗?