【发布时间】:2015-12-30 09:38:56
【问题描述】:
您好,我正在尝试在 cakephp 中上传图像,但它仅在数据库表中插入 jpg 时出现错误
警告 (2): move_uploaded_file(C:\xampp\htdocs\practise\app\webroot\img\image\3.jpg): 无法打开流: 没有这样的文件或目录 [APP\Controller\UsersController.php ,第 98 行]
警告 (2): move_uploaded_file() [function.move-uploaded-file]: 无法将 'C:\xampp\tmp\php24B4.tmp' 移动到 'C:\xampp\htdocs\praactise\app\webroot \img\image\3.jpg' [APP\Controller\UsersController.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();?>
【问题讨论】:
标签: cakephp