简体   繁体   中英

Get file codeigniter upload file

I'm recently uploading multiple file (xml), I'm success on this part. But i've problem when i want to get the full_path . I need to access the full_path because i need this to save the xml file.

Here is what i get after upload.

$file = $this->upload->data('full_path');
echo "<pre>"; print_r($file);

Array
(
    [0] => Array
        (
            [file_name] => SALESPOS_K-LFJBLP_16-07-1410.xml
            [file_type] => text/xml
            [file_path] => D:/xampp/htdocs/new_store/assets/file_upload/sales_pos/
            [full_path] => D:/xampp/htdocs/new_store/assets/file_upload/sales_pos/SALESPOS_K-LFJBLP_16-07-1410.xml
            [raw_name] => SALESPOS_K-LFJBLP_16-07-1410
            [orig_name] => SALESPOS_K-LFJBLP_16-07-14.xml
            [client_name] => SALESPOS_K-LFJBLP_16-07-14.xml
            [file_ext] => .xml
            [file_size] => 93.38

        )

    [1] => Array
        (
            [file_name] => SALESPOS_K-LFJBLP_16-07-1310.xml
            [file_type] => text/xml
            [file_path] => D:/xampp/htdocs/new_store/assets/file_upload/sales_pos/
            [full_path] => D:/xampp/htdocs/new_store/assets/file_upload/sales_pos/SALESPOS_K-LFJBLP_16-07-1310.xml
            [raw_name] => SALESPOS_K-LFJBLP_16-07-1310
            [orig_name] => SALESPOS_K-LFJBLP_16-07-13.xml
            [client_name] => SALESPOS_K-LFJBLP_16-07-13.xml
            [file_ext] => .xml
            [file_size] => 47.43
        )
)

and here is for my XML handle

$file = $this->upload->data('full_path'); ;
$xml=simplexml_load_file($file);

and i get this error

Message: simplexml_load_file() expects parameter 1 to be a valid path, array given

Simple typo I guess

change this :

$file = $this->upload->data('full_path'); ;

to this :

$file = $this->upload->data('full_path');

or you can try :

$data = $this->upload->data();
$file = $data['full_path'];
$xml=simplexml_load_file($file);

for a multiple upload :

foreach($file as $each)
{
 $xml=simplexml_load_file($each['full_path']);
}

Try this

$xml            = array();
$data = $this->upload->data();
for($x = 0;$x<count($data);$x++)
    {
         $xml[]=simplexml_load_file($data[$x]['full_path']);
    }
echo "<pre>";print_r($xml);

$file is an array not the file. Do like this.

foreach($file as $file_val){
  $file_path = $file_val['full_path'];
  $xml=simplexml_load_file($file_path);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM