Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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
Php Codeigniter 2.1-文件上载您没有选择要上载的文件_Php_Codeigniter_Codeigniter 2 - Fatal编程技术网

Php Codeigniter 2.1-文件上载您没有选择要上载的文件

Php Codeigniter 2.1-文件上载您没有选择要上载的文件,php,codeigniter,codeigniter-2,Php,Codeigniter,Codeigniter 2,模型函数: public function file_upload($folder, $allowed_type, $max_size = 0, $max_width = 0, $max_height = 0) { $folder = $this->path . $folder; $files = array(); $count = 0; foreach ($_FILES as $key => $value)

模型函数:

public function file_upload($folder, $allowed_type, $max_size = 0, $max_width = 0, $max_height = 0)
    {
        $folder = $this->path . $folder;

        $files = array();
        $count = 0;

        foreach ($_FILES as $key => $value) :

            $file_name = is_array($value['name']) ? $value['name'][$count] : $value['name'];
            $file_name = $this->global_functions->char_replace($file_name, '_');
                $count++;
                $config = array(
                'allowed_types' => $allowed_type,
                'upload_path'   => $folder,
                'file_name'     => $file_name,
                'max_size'      => $max_size,
                'max_width'     => $max_width,
                'max_height'    => $max_height,
                'remove_spaces' => TRUE
                 );

        $this->load->library('image_lib');
            $this->image_lib->clear();
            $this->load->library('upload');
            $this->upload->initialize($config);

            if (!$this->upload->do_upload($key)) :
                $error = array('error' => $this->upload->display_errors());
            var_dump($error);
                return FALSE;
            else :
                $file = $this->upload->data();
                $files[] = $file['file_name'];
            endif;

        endforeach;

        if(empty($files)):
            return FALSE;
        else:
            return implode(',', $files);
        endif;
    }

此功能正在部分工作。文件正在上载到所选文件夹,但我收到了以下错误:您没有选择要上载的文件。结果是为FALSE?有什么问题吗?(表单使用的是表单\u open\u multipart

请确保您的文件标记字段有以下名称:

   $key='userfile' //which is name of input type field name

发生这种情况时,是否有任何文件输入为空<代码>$\u如果没有为输入指定文件,则文件将包含一个“空”数据数组。例如,我的文件输入名是
one
,我提交它时没有指定文件:

Array
(
    [one] => Array
        (
            [name] => 
            [type] => 
            [tmp_name] => 
            [error] => 4
            [size] => 0
        )
)

在处理上载之前,应检查文件数据是否为空。PHP在这方面很有用。

文件上传有几个输入字段,因此它们都必须有不同的名称。另一方面,当您有$this->upload->do_upload($key)时,函数将知道它所指的字段;我做了所有这些,还是什么都没做。您是否在文件输入名上使用了
[]
?如果是,则您的
$\u文件
数组不包含您期望的
键。看看