获取文件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

试试这个

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

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

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