Error loading XML in Laravel

-2

I'm getting the error below when loading XML using Laravel. I tested the import with pure PHP and it was normal. Anyone have any idea what that might be? I understand that " is quotation marks, but I did not find it in XML.

simplexml_load_file(): I/O warning : failed to load external entity ""

Code line where the error occurs:

$xml = simplexml_load_file($request->file('publicacao')); dd($xml
    
asked by anonymous 28.08.2018 / 14:52

1 answer

1

As far as I understand the $request->file() (returns Illuminate\Http\UploadedFile ) of Laravel does not return a string, even if you look in the documentation you will notice that there is no __toString which should be the minimum for the first to return the temporary path of the file you are uploading, see the documentation:

So probably when passing the value to simplexml_load_file it is looking for a file that is not the correct file, probably what is between "" , what it was trying to pass was an object, so probably:

object(Illuminate\Http\UploadedFile)#1 (0) {
}

warning errors are likely to be turned off or hidden, but if it were on it would display something like:

  

PHP Warning: simplexml_load_file () expects parameter 1 to be a valid path, object given

The phrase object given means that you have taken an object, the previous phrase says, parameter 1 must be a valid path, ie object is not path and not string.

How to read% content of laravel

Probably the correct one would be to use UploadedFile + UploadedFile::get() , like this:

$xml = simplexml_load_string($request->file('publicacao')->get());
dd($xml);
    
28.08.2018 / 18:01