[英]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.