我是CodeIgniter的初学者。我正在尝试获取我上传的一个文件的属性,如名称,类型等。但我无法检索该信息。它正在输出一个空数组。我做错了什么?我试过了:
function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = '999999';
$config['max_width'] = '3000';
$config['max_height'] = '2000';
$this->load->library('upload', $config);
$details = $this->upload->data();
echo "<pre>";
print_r ($details);
echo "</pre>";
if (!$this->upload->do_upload()){
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $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] =>
)
答案 0 :(得分:1)
$this->upload->data()
将在执行$this->upload->do_upload()
后返回上传的数据。所以试试你的else
部分。
有关详细信息,请参阅CI用户Guide