Returning XML files inside a PHP folder

Asked

Viewed 88 times

0

I am using the following code to list and read the XML files in this folder. But how the listing returns me . and the .. my system returns error that cannot access these files. It follows the codes used.

$pasta = $data[0].$data[1].$data[2]."_".$data_end[0].$data_end[1].$data_end[2];
$l_nfe = dir("xml/".$pasta);

while($arquivo = $l_nfe -> read()){
    simplexml_load_file("xml/".$pasta."/".$arquivo);
}

The string returns me "xml/01042018_30042018/.." could someone help me to list these xml files and load them to display the content.

1 answer

0


You have to add exection to these two directories this way.

$pasta = $data[0].$data[1].$data[2]."_".$data_end[0].$data_end[1].$data_end[2];
$l_nfe = dir("xml/".$pasta);

while($arquivo = $l_nfe -> read()){
    if($arquivo !== "." && !$arquivo !== ".."){
       simplexml_load_file("xml/".$pasta."/".$arquivo);
    }
}
  • Thanks brother worked! I didn’t think of this possibility... rsrs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.