servo-php / fluidxml

FluidXML, the PHP library for manipulating XML with a concise and fluent API.
BSD 2-Clause "Simplified" License
458 stars 45 forks source link

Getting error when using FluidXml::load #10

Closed uxweb closed 8 years ago

uxweb commented 8 years ago

Hi!, thanks for created this awesome package!

I'm having an issue while loading an xml file from an html form.

This is how i'm trying to load the file:

$xml = FluidXml::load($request->file('cfdi')->path());

// $request->file('cfdi')->path() -> this gives me the temp path of the uploaded file

And this is the error i'm getting:

Undefined index: <?xml version="1.0" encoding="UTF-8"?><cfdi

I'm attaching the file as well :)

ED545AAA-23FB-4362-859C-61ACADF5FD37.xml.zip

I don't think it is a malformed xml because i have several of them and the same error occurs with all.

I will appreciate any advice you can give me to solve this issue.

Thank you!

daniele-orlando commented 8 years ago

Hi dear Uziel, which version of FluidXML are you using?

Please can you attach the output of

var_dump($request->file('cfdi')->path());

Thanks.

uxweb commented 8 years ago

Hi @daniele-orlando , thanks for answering!

I'm using version 1.20.2,

The output of the uploaded file path is:

"/private/var/tmp/phpzZX0IA"

I also tried to load a file from my public directory without using a form but i get the same error.

Is there something else i'm missing?

Thanks!

daniele-orlando commented 8 years ago

OK, thank you. I'm out for the weekend, I'll investigate the issue Monday.

uxweb commented 8 years ago

@daniele-orlando Thank you so much!

Have a great weekend! 👌

daniele-orlando commented 8 years ago

@uxweb The problem is in your XML files which begin with the UTF-8 (invisible) BOM character. UTF-8 files should never have the BOM character, which leads to many problems as you have seen by yourself.

See this post on StackOverflow on how to remove the BOM character.