I have an odd thing happening that I've been trying to fix for two days. I have a script on a server that generates an Excel file using Excel::Writer::XLSX to create a file with an extension of .xlsx. It creates an excel file that, if I download with FTP, opens properly and with no issues.
The problem is that the user won't have FTP access and will need to use a download link. As the file is written to a location outside of normal web space, I have a script that facilitates the download. I've been using it with text files and there is no issue.
I've also used this same format in the past for other binary files (JPG, PDF, Word, etc) and have not had a problem.
What is happening is that when I click on the downloaded file to open it I get first a message that says:
"We found a problem with some content in FILENAME. Do you want us to try recover as much as we can? If you trust the source of the workbook, click Yes."
When I click YES I get the message that says it was trying to open and repair the file, but nothing happens.
I know the file is okay because I can retrieve it over FTP and it opens fine. So the problem must be in the download itself.
I'm using the mime-type "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" and I've also tried "application/vnd.ms-excel"
Here is the portion of the code that does the download. (It is used for both binary and text files.)
if(open(FH, "<$filepath")) { print "Content-Type:$mimetype; name = \"$filename\"\n"; print "Content-Disposition: attachment; filename = \"$filename\"\n +\n"; while( my $line = <FH>) { #I am chomping then adding new lines because the UNIX line fee +ds are not #recognized on some winderz computerz apps. This is why I stri +p the UNIX line #feed (\n) and then add a Windows line feed (\r\n) if($mimetype eq 'text/plain') { chomp($line); print $line, "\r\n"; } else { print $line; } } close(FH); print "EOF\n\n"; exit; } else { &error_page; }
Server Software: LiteSpeed
Operating System: Linux
Perl version: 5.016003
I've tried downloading this on a 2-year old Windows11 operating system in Chrome version 109.
I've tried downloading this on a 10-year old laptop with Windows 8 operating system in Chrome version 109.
I've also tried downloading from Microsoft Edge 109, Firefox 86
I'm really bugged by this (pun intended) because I've done this same thing with many file types in the past (but never Excel) and never had a problem, binary or text.
Does anyone have experience with this problem and know what it is I'm doing wrong?
Thank you for your time and wisdom.
In reply to Download from Perl script corrupted for XLSX file. by TorontoJim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |