Error loading XML into Laravel

Asked

Viewed 207 times

-2

I am getting the error below when loading XML using Laravel. I tested the import with pure PHP and it was normally. Does anyone have any idea what it might be? I understand that " is quotes, but not found 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
  • According to this question, the simplexml_load_file() expecting a filename, you’re passing that?

  • Yes. You have another alternative to him?

  • Put the full code snippet, including the line that returns this error, makes it easy for us to better understand the problem.

  • $xml = simplexml_load_file($request->file('publish')); dd($xml); .

  • Put what is the content of $request->file('publicacao').

  • No da. The file is too large. I tried to put the content in Pastebin but exceeded the maximum size.

Show 1 more comment

1 answer

1

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

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

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

It is very likely that the mistakes of Warning are turned off or hidden, but if turned on 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 it took an object, the previous sentence says, parameter 1 must be a valid path, that is, object is not path nor string.


How to read the contents of UploadedFile of the Laravel

Probably the right thing to do UploadedFile::get() + simplexml_load_string(), thus:

$xml = simplexml_load_string($request->file('publicacao')->get());
dd($xml);

Browser other questions tagged

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