我无法获取我上传的文件Codeigniter的file_name

时间:2015-01-27 14:39:37

标签: php codeigniter

这是我的问题,我无法获取上传的file_name。这是我的代码:

控制器:

$file = array('upload_data' => $this->upload->data());
echo 'value =>'.$file['file_name'];
print_r($file);

结果:

A PHP Error was encountered

Severity: Notice

Message: Undefined index: file_name

Filename: controllers/uploading.php

Line Number: 38
value =>Array ( [upload_data] => Array ( [file_name] => Capture9.JPG [file_type] => image/jpeg [file_path] => C:/xampp/htdocs/Internship/asset/admin/img/ [full_path] => C:/xampp/htdocs/Internship/asset/admin/img/Capture9.JPG [raw_name] => Capture9 [orig_name] => Capture.JPG [client_name] => Capture.JPG [file_ext] => .JPG [file_size] => 30.88 [is_image] => 1 [image_width] => 589 [image_height] => 297 [image_type] => jpeg [image_size_str] => width="589" height="297" ) ) 

RMK>上传工作,但我只需要获取文件名。感谢

2 个答案:

答案 0 :(得分:0)

file_name是您定义的名为$file的数组的属性。您想使用$file['upload_data']['file_name']来访问它。

答案 1 :(得分:0)

注意多维阵列

您试图访问['uploaded_data']数组内部数组中的索引!所以你必须使用$file['uploaded_data']['file_name'],以便检查该数组的isset索引是否更好! :)