How to get full path of the uploaded file in codei

2019-05-26 03:49发布

问题:

I am using codeIgniter file uploading class example https://www.codeigniter.com/user_guide/libraries/file_uploading.html to upload files. In the example after i uploaded files it will show details like below in the upload success view page.

 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] => 
    )

 )

Afterwards I tried to see entire uploaded data in an array format. My question is how to get full file path from the above array. I know there is a variable full_path but I am not able to get it. Please help me.

回答1:

From your controller use

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

From your view use

echo $upload_data['full_path'];


回答2:

Try like this:

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

        }


回答3:

From you post, I am assuming that you have given output from print_r of some variable, say $file_detail.

If you want to get the full_path from $file_detail, you have to use

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


回答4:

The array is returned upon succesful upload, you just need to retrieve the index key:

Controller:

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>


回答5:

if you want to delete a file from uploads after inserting into database you can remove file from uploads using unlink($filename)