如何在codeigniter中获取上传文件的完整路径?

问题描述 投票:2回答:5

我正在使用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但我无法得到它。请帮我。

php codeigniter
5个回答
3
投票

从您的控制器使用

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

从您的角度来看

echo $upload_data['full_path'];

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'];

        }

1
投票

从你发布,我假设你已经从某个变量的print_r给出了输出,比如$file_detail

如果你想从$file_detail获得full_path,你必须使用

$file_detail['upload_data']['full_path']

0
投票

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

控制器:

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

myview.php

<p>Full path: <?php echo $upload_data['full_path'];?></p>

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.