关于php:图片上传数据为空

Image upload data empty

当前具有这些代码。

1
2
3
4
5
6
    $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);

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

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

但是数据库行是空的,所以我检查了一下自己。 I print_r($image_data)是模型函数的第一个参数。仍然空着,以确保更早。我输入了。

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

不过,结果还是空白。

Array ( [file_name] => [file_type] => [file_path] => ./uploads/
[full_path] => ./uploads/ [raw_name] => [orig_name] => [client_name]
=> [file_ext] => [file_size] => [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => )

编辑:

1
2
3
4
5
6
7
8
9
10
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());
}


如果您为input file control命名了任何名称,则在使用此do_upload函数时必须设置该名称。

例如

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

默认情况下,上传例程希望文件来自名为userfile的表单字段,并且该表单必须为" multipart type

请参见参考文献$this->upload->do_upload()

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

上面链接

Function Reference下的