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

时间:2012-10-31 06:34:27

标签: php codeigniter

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

5 个答案:

答案 0 :(得分: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 :(得分:3)

从您的控制器使用

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

从您的视图中使用

echo $upload_data['full_path'];

答案 2 :(得分:1)

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

如果您想从$file_detail获取full_path,则必须使用

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

答案 3 :(得分: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>

答案 4 :(得分:0)

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