Hi Iam尝试在cakephp中上载图像,但它仅在数据库表中插入jpg,Iam收到的错误如下:
警告(2):move_uploaded_file(C:\xampp\htdocs\实践\app\webroot\img\Image\3.jpg):打开流失败:没有这样的文件或目录[APP\Controller\UsersController.php,第98行]
警告(2):移动上传的文件()[函数.移动上传的文件]:无法移动'C:\xampp\tmp\php24B4。tmp'到'C:\xampp\htdocs\practice\app\webroot\img\image\3。jpg'[APP\Controller\userscoontroller.php,第98行]
这是我的密码
控制器:
$extension =strtolower(pathinfo($this->request->data['User']['image_file']['name'],PATHINFO_EXTENSION));
if(
!empty ($this->request->data['User']['image_file']['tmp_name'])&&
in_array($extension,array('png','jpeg','jpg'))
)
{
move_uploaded_file
(
$this->request->data['User']['image_file']['tmp_name'],
IMAGES.'image'.DS.$this->User->id.'.'. $extension
);
$this->User->saveField('image',$extension);
}
elseif(!empty ($this->request->data['User']['image_file']['tmp_name']))
和视图:
<?php echo $this->Form->create('User',array('type' =>'file'));?>
<?php echo $this->Form- >input('image_file',array('label'=>'Image(jpeg,jpg,png)','type' =>'file'));?>
<?php echo $this->Form->end();?>
确保您的图像文件夹路径正确吗?
C:\xampp\htdocs\practice\app\webroot\img\image\3。jpg
图像文件夹存在于您的img文件夹中?
请更换这个
move_uploaded_file($this->request->data['User']['image_file']['tmp_name'],IMAGES.'image'.DS.$this->User->id.'.'. $extension);
$this->User->saveField('image',$extension);
到
move_uploaded_file($this->request->data['User']['image_file']['tmp_name'],IMAGES.'image'.DS.$this->request->data['User']['image_file']['name']);
$this->User->saveField('image',$this->request->data['User']['image_file']['name']);