获取文件codeigniter上传文件

时间:2016-07-19 09:32:41

标签: php arrays xml codeigniter

我最近上传了多个文件(xml),我在这方面取得了成功。但是当我想要获得full_path时,我有问题。我需要访问full_path因为我需要这个来保存xml文件。

这是我上传后得到的内容。

$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
        )
)

这是我的XML句柄

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

我收到此错误

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

3 个答案:

答案 0 :(得分:1)

简单错字我猜

改变这个:

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

到此:

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

或者您可以尝试:

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

进行多重上传:

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

答案 1 :(得分:1)

试试这个

$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);

答案 2 :(得分:0)

$ file是一个数组而不是文件。这样做。

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