简体   繁体   English

获取文件codeigniter上传文件

[英]Get file codeigniter upload file

I'm recently uploading multiple file (xml), I'm success on this part. 我最近上传了多个文件(xml),这部分我很成功。 But i've problem when i want to get the full_path . 但是我想获取full_path时遇到问题。 I need to access the full_path because i need this to save the xml file. 我需要访问full_path因为我需要它来保存xml文件。

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 这是我的XML句柄

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

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