图片上传数据为空

时间:2014-02-28 19:36:59

标签: php codeigniter file-upload

目前有这些代码。

    $config['upload_path'] = './uploads/';
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '1000';
                $config['max_width']  = '270';
                $config['max_height']  = '280';
$this->load->library('upload', $config);

然后将详细信息插入数据库。

$this->Model->upload_image($this->upload->data(),$result_id);

但db行是空的所以我检查了自己。我print_r($image_data)这是模型函数的第一个参数。仍然空虚,以确保即使是铁道部。我输入了。

print_r($this->upload->data());

然而,结果却是空洞的。

  

数组([file_name] => [file_type] => [file_path] => ./uploads/   [full_path] => ./uploads/ [raw_name] => [orig_name] => [客户名称]   => [file_ext] => [file_size] => [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => )

编辑:

if ( ! $this->upload->do_upload())
            {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('view', $error);
            }
            else
            {
            $image_data = array('upload_data' => $this->upload->data());
            print_r($this->upload->data());
}

1 个答案:

答案 0 :(得分:1)

如果您为input file control提供了名称,则必须在使用此do_upload功能时将其设置为

例如

$field_name = "some_field_name";
$this->upload->do_upload($field_name) 

默认情况下,上传例程要求文件来自名为 userfile 的表单字段,表单必须是“多部分类型

参见参考$this->upload->do_upload()

http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

在上面的Function Reference链接