繁体   English   中英

获取文件codeigniter上传文件

[英]Get file codeigniter upload file

我最近上传了多个文件(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

我猜简单的错字

改变这个:

$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']);
}

尝试这个

$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是一个数组而不是文件。 这样吧

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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