Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cakephp检索文件数据上传_Php_Image_Cakephp_Upload - Fatal编程技术网

Cakephp检索文件数据上传

Cakephp检索文件数据上传,php,image,cakephp,upload,Php,Image,Cakephp,Upload,在我的表格上,我有一个上传输入 echo $this->Form->input('imagem', array('type'=>'file')); 当它试图检查“imagem”输入中的大小、类型和加载所有数组数据时,它就是不能 function uploadImagem() { $file = $this->data['Produto']['imagem']; print_r($file); if ($file['error'] === UPLO

在我的表格上,我有一个上传输入

echo $this->Form->input('imagem', array('type'=>'file'));
当它试图检查“imagem”输入中的大小、类型和加载所有数组数据时,它就是不能

function uploadImagem() {
    $file = $this->data['Produto']['imagem'];
    print_r($file);
    if ($file['error'] === UPLOAD_ERR_OK) {
        $id = String::uuid();
        if (move_uploaded_file($file['tmp_name'], APP.'uploads'.DS.$id)) {
          $this->data['Upload']['id'] = $id;
          $this->data['Upload']['user_id'] = $this->Auth->user('id');
          $this->data['Upload']['filename'] = $file['name'];
          $this->data['Upload']['filesize'] = $file['size'];
          $this->data['Upload']['filemime'] = $file['type'];
          return true;
        }
    }
    return false;
}
当我打印$file时,它应该显示“Array()”,但它正在检索文件名。 如果我尝试使用/print
$this->data['Produto']['imagem']['name']
$this->data['Produto']['imagem']['error']
,它只会给我一个错误

非法字符串偏移量“name”


有人能告诉我如何使用Cakephp正确上传吗

您的
$\u文件
只是一个文件名而不是数组,这表明您的表单没有
enctype=“multipart/form data”
。 使用Cake,您可以使用
FormHelper
()实现这一点:



另外,为了在CakePHP中管理文件上传,我建议您使用这个很棒的插件:

您是否在
表单->创建中使用了
'type'=>'file'
,谢谢您的提示!但还是不行!你能给我一个如何安装或使用这个插件的链接吗?这里有文档:
<?= $this->Form->create('Mymodel', array('type' => 'file')) ?>