2

我正在使用 codeIgniter 文件上传类示例https://www.codeigniter.com/user_guide/libraries/file_uploading.html 来上传文件。在我上传文件后的示例中,它将在上传成功视图页面中显示如下详细信息。

 Array
(
[upload_data] => Array
    (
        [file_name] => VenkataKrishna10.pdf
        [file_type] => application/pdf
        [file_path] => C:/xampp/htdocs/upload/application/
        [full_path] => C:/xampp/htdocs/upload/application/VenkataKrishna10.pdf
        [raw_name] => VenkataKrishna10
        [orig_name] => VenkataKrishna.pdf
        [client_name] => VenkataKrishna.pdf
        [file_ext] => .pdf
        [file_size] => 83.27
        [is_image] => 
        [image_width] => 
        [image_height] => 
        [image_type] => 
        [image_size_str] => 
    )

 )

之后我尝试以数组格式查看整个上传的数据。我的问题是如何从上面的数组中获取完整的文件路径。我知道有一个变量full_path,但我无法得到它。请帮我。

4

5 回答 5

3

试试这样:

         if ( ! $this->upload->do_upload())
        {
            $error = array('error' => $this->upload->display_errors());

        }
        else
        {
            $data = $this->upload->data();
                    // $data will contain full inforation
                    echo "Full path is:". $data['full_path'];

        }
于 2012-10-31T06:51:38.267 回答
3

从您的控制器使用

echo $data['upload_data']['full_path'];

从你的角度来看使用

echo $upload_data['full_path'];
于 2012-10-31T07:08:45.880 回答
1

从您的帖子中,我假设您已经从 print_r 给出了某个变量的输出,例如$file_detail.

如果要从中获取 full_path $file_detail,则必须使用

$file_detail['upload_data']['full_path']
于 2012-10-31T07:08:55.950 回答
0

上传成功返回数组,你只需要检索索引键:

控制器:

if ( ! $this->upload->do_upload())
{
     $data['error'] = $this->upload->display_errors();
}
else
{
   $data['upload_data'] = $this->upload_data();
}
$this->load->view('myview', $data);

我的视图.php

<p>Full path: <?php echo $upload_data['full_path'];?></p>
于 2012-10-31T06:37:38.483 回答
0

如果您想在插入数据库后从上传中删除文件,您可以使用 unlink($filename) 从上传中删除文件

于 2013-05-08T11:36:23.483 回答