Hi All,
I have written an cgi perl script that displays an image(Excel image) and when clicked on that Image I need to download a excel sheet.
I made sure that excel sheet exists in the folder with the given name but still I am not able to download the sheet.
print "<center><table border=0>";
print "<tr><td aligh=left>";
print qq~<a href="$report_name"><img src="http://mywebsite.com/images/xlsx.png" width=40 height=40></a>~;
print qq~<a href="$report_name><img src="http://mywebsite.com/images/csv.jpg" width=40 height=40></a>~;
print "</td></tr>";
print "</table></center>";
I learned that we need to add the below lines for download the files using cgi perl.
print ("Content-Type:application/x-download\n");
print "Content-Disposition: attachment; filename=$report_name\n\n";
After adding ...
print ("Content-Type:application/x-download\n");
print "Content-Disposition: attachment; filename=$report_name\n\n";
print "<center><table border=0>";
print "<tr><td aligh=left>";
print qq~<a href="$report_name"><img src="http://mywebsite.com/images/xlsx.png" width=40 height=40></a>~;
print qq~<a href="$report_name><img src="http://mywebsite.com/images/csv.jpg" width=40 height=40></a>~;
print "</td></tr>";
print "</table></center>";
But only the above 2 lines on the browser and no luck...
Could anyone please let me know what went wrong ??
I am attaching the complete script with the thread.
(download statements are written in 311 and 312 lines)
Tons of thanks .....
Regards,
J
I think you misunderstood some advice from somewhere.
Content-type
supplies a mime type for the browser to enable it to load a helper application or if it has none to offer to save the file.
Once your httpd is configured correctly, all you have to do is print <a href="http://$myhost/http/path/to/spreadsheet><img src="/images/excell.gif"></a>
to the browser. unless you're publishing the spreadsheet directly (mention of looking at line 300 for the spreadsheet scared me off reading your script ) if you are generating and printing the spreadsheet from a script then no HTML should be sent and you should really use the correct mime type for the spreadsheet in the header information sent to the browser [icode]content-type: application/vnd.ms-excel[/code]
1 Like
Thanks Skrynesaver...!!!!
I have replaced the lines to the below but still no luck.
print ("Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\n");
print "Content-Disposition: attachment; filename=$report_name\n";
When clicking o the Image button, instead of getting the excel file the page is redirect to the error screen.
Could you please let me know whether any other changes are required ?
I have configured the httpd.conf to run the cgi scripts.I have presently saved all the cgi fiiles in /cgi-bin/subfolder/ directory.
Are there any other configuration changes that has to be made to download the excel sheet.
And also I tried to copy the excel file(in /cgi-bin/subfolder) that is generated through cgi script to some other directory outside cgi-bin.But it is showng an error message.
Could you please let me know how to come out of this issue ?