Weird chars when downloading an Excelfile from the Panel

Hi
By the phpspreadsheet plugin I’ve created an excelfile which logs form queries.
When I first download this file via the panel,

then it shows weird chars like this in LibreOffice:

When just download it again, then the excelfile is displayed correctly.
I first thought that that file has not been downloaded completely.
But it does not matter how long I wait. The file is very small anyway.

Any idea what is going wrong?

Kind regards
Alain

LibreOffice was trying to open the file via its text import assistent. It is meant for CSV files, not Excel files. Excel files are compressed, so it‘s expected that the file contents look like garbage when viewed as a text file.

But why does LibreOffice interpret the file correctly only on the second try?

How did you open it? Double-click in your file manager or from LibreOffice?

Directly from the browser download (one click):

OK, makes sense.

I just noticed that there are two empty lines at the beginning of the file from your first screenshot. I think the issue could be caused by that.

Which web server (Apache, nginx…) do you use and is it in your local network or public?

It is on a hosting (public), but the same behaving locally.
Here are the Apache and nginx settings of the hosting:

Does the same problem occur if you open the file directly from the content folder?

And has it occurred again since you first had the issue? Or did it only occur once and then worked after that?

No.

It has occured again.

That’s all very weird.

Kirby itself can’t be the cause as the link behind the “Open” button points directly to the file in the media folder. On the first request this file gets copied by Kirby, but if this issue keeps occurring, it can’t be that.

Subsequent requests get handled directly by your web server (in this case most likely directly by nginx, but maybe by Apache and then forwarded by nginx).

What makes it even more weird is that you see the same behavior locally. So just to make sure we are on the same page: Does the issue occur on each “first” request after modifying or creating the Excel file with the plugin? Or did it also occur in such a subsequent request (when it has worked before without changes to the file but then doesn’t work again)?

Or did it also occur in such a subsequent request (when it has worked before without changes to the file but then doesn’t work again)?

No, it always occurs on the first download after the creation/update of the excelfile.
For every download after it always works.
I have tested it in combination with different browsers locally.
After creation/update of the File I downloaded it from Browser A > “error”
Then I did download it again on the same Browser and on Browser B > everthing ok
Then I did update the file and downloaded it on Browser B > “error”
Then downloading it on Browser A > everthing ok

OK, now I feel like we are getting closer. :slight_smile:

Do you have any plugins installed? If so, please check all PHP files inside the plugins for extraneous empty lines. These most often occur at the start or end of the file before the <?php tag or after a ?> tag if defined.

Also check your config files inside site/config and models in site/models if you have any.

If you found any empty lines, remove them.

Wow thanks, that was it!
You are a genious :smiley:

1 Like