Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Why this file download CGI works with Firefox and fails with IE ?

Reply
Thread Tools

Why this file download CGI works with Firefox and fails with IE ?

 
 
Us
Guest
Posts: n/a
 
      11-16-2007
Hello everybody,

I've a problem with a file download script written in Perl. When I call
it from Firefox it's OK, but when I call it from IE, it's not.

The IE download dialog is launched, but IE try to search info about the
file and fails to do-it. Thus, I get an error message saying "IE cannot
download download.cgi?test.rar from www..."

What's the problem with this script and IE ?


The code is this :
#!/usr/bin/perl -w

use CGI ':standard';

my $ID = param('ID');
my $files_location = "../httpdocs/repository";
my @fileholder;

if ($ID eq ''){
print "Content-type: text/html\n\n";
print "no file parameter";}
else{
open(DLFILE, "<$files_location/$ID") || Error('open', 'file');
binmode DLFILE;
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');

open (LOG, ">>download.log") || Error('open', 'file');
print LOG "$ID\n";
close (LOG);

binmode STDOUT;
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder}

sub Error{
print "Content-type: text/html\n\n";
print "server can't $_[0] the $_[1]: $! \n";
exit;}

It's called using url like (here a fictive one) :
http://www.mydomain.org/cgi-bin/down...gi?ID=test.rar
knowing test.rar is present in the repository directory.
 
Reply With Quote
 
 
 
 
A. Sinan Unur
Guest
Posts: n/a
 
      11-16-2007
Us <(E-Mail Removed)> wrote in news:MPG.21a800bb1d732e46989972
@news.tiscali.fr:

> Hello everybody,

....

> What's the problem with this script and IE ?


The script has many problems other than the one you are experiencing.

> The code is this :
> #!/usr/bin/perl -w


use strict;

> use CGI ':standard';
>
> my $ID = param('ID');


You are not running any checks against ID.

> my $files_location = "../httpdocs/repository";
> my @fileholder;
>
> if ($ID eq ''){
> print "Content-type: text/html\n\n";


Why are you lying about the content type?

> print "no file parameter";}
> else{
> open(DLFILE, "<$files_location/$ID") || Error('open', 'file');


Oh, nice. This way, I can download any file on your system.

> binmode DLFILE;
> @fileholder = <DLFILE>;


There is no need to slurp the whole file. Just read chunks of it (using
sysread and echo back out.

> close (DLFILE) || Error ('close', 'file');
>
> open (LOG, ">>download.log") || Error('open', 'file');
> print LOG "$ID\n";
> close (LOG);
>
> binmode STDOUT;
> print "Content-Type:application/x-download\n";


AFAIK, a space is needed between the colon and the MIME type.

Use CGI.pm to generate headers.

Sinan

--
A. Sinan Unur <(E-Mail Removed)>
(remove .invalid and reverse each component for email address)
clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>

 
Reply With Quote
 
 
 
 
Us
Guest
Posts: n/a
 
      11-16-2007
In article <Xns99EA8F7928ECEasu1cornelledu@127.0.0.1>,
http://www.velocityreviews.com/forums/(E-Mail Removed)d says...
> The script has many problems other than the one you are experiencing.
>


OK, it seems to be a bad CGI (from Web), but does all you say explain
the reason why it doesn't works with IE while it works (even if ugly)
with Firefox ?
 
Reply With Quote
 
Jürgen Exner
Guest
Posts: n/a
 
      11-16-2007
Us wrote:
> In article <Xns99EA8F7928ECEasu1cornelledu@127.0.0.1>,
> (E-Mail Removed)d says...
>> The script has many problems other than the one you are experiencing.

>
> OK, it seems to be a bad CGI (from Web), but does all you say explain
> the reason why it doesn't works with IE while it works (even if ugly)
> with Firefox ?


You may want to ask in a nNewsgroup that actually deals with web
programming, CGI, and differences between different web browsers.

Or to put it the other way: if this script were written in C or Modula
producing exactly the same behaviour/output as your Perl script, would you
expect IE "to work"?

jue


 
Reply With Quote
 
smallpond
Guest
Posts: n/a
 
      11-16-2007
On Nov 16, 1:32 pm, Us <(E-Mail Removed)> wrote:
> Hello everybody,
>
> I've a problem with a file download script written in Perl. When I call
> it from Firefox it's OK, but when I call it from IE, it's not.
>
> The IE download dialog is launched, but IE try to search info about the
> file and fails to do-it. Thus, I get an error message saying "IE cannot
> download download.cgi?test.rar from www..."
>
> What's the problem with this script and IE ?
>
> The code is this :
> #!/usr/bin/perl -w
>
> use CGI ':standard';
>
> my $ID = param('ID');
> my $files_location = "../httpdocs/repository";
> my @fileholder;
>
> if ($ID eq ''){
> print "Content-type: text/html\n\n";
> print "no file parameter";}
> else{
> open(DLFILE, "<$files_location/$ID") || Error('open', 'file');
> binmode DLFILE;
> @fileholder = <DLFILE>;
> close (DLFILE) || Error ('close', 'file');
>
> open (LOG, ">>download.log") || Error('open', 'file');
> print LOG "$ID\n";
> close (LOG);
>
> binmode STDOUT;
> print "Content-Type:application/x-download\n";
> print "Content-Disposition:attachment;filename=$ID\n\n";
> print @fileholder}
>
> sub Error{
> print "Content-type: text/html\n\n";
> print "server can't $_[0] the $_[1]: $! \n";
> exit;}
>
> It's called using url like (here a fictive one) :http://www.mydomain.org/cgi-bin/down...gi?ID=test.rar
> knowing test.rar is present in the repository directory.


What's in the webserver error log?
 
Reply With Quote
 
Us
Guest
Posts: n/a
 
      11-16-2007
In article <514c4016-102d-4742-a6ec-bf9da09c65c0
@y5g2000hsf.googlegroups.com>, (E-Mail Removed) says...
>
> What's in the webserver error log?
>


Unfortunately, nothing in error_log.

The download dialog box is well displayed by IE, but it search for file
info and one second later, says it cannot found it.
 
Reply With Quote
 
Us
Guest
Posts: n/a
 
      11-16-2007
In article <S5m%i.83$B21.52@trndny07>, (E-Mail Removed) says...
>
> You may want to ask in a nNewsgroup that actually deals with web
> programming, CGI, and differences between different web browsers
>


Good idea, I'll do it in parralel with the current topic. Thanks you.
 
Reply With Quote
 
Us
Guest
Posts: n/a
 
      11-17-2007
In article <fhll1p$1tff$(E-Mail Removed)>, (E-Mail Removed) says...
> take a look to packet log what headers server sent.
>


Thank you for. The different headers received are those (notice I've
switched to a test.zip rather than test.rar just because I had a smaller
one ready for testing) :

When I download directly :
(Status-Line) HTTP/1.0 200 OK
Accept-Ranges bytes
Connection keep-alive
Content-Length 145281
Content-Type application/zip
Date Sat, 17 Nov 2007 10:13:19 GMT
ETag "578da31-23781-43bc5911c7500"
Last-Modified Fri, 05 Oct 2007 21:27:16 GMT
Server Apache/2.2.3
Via 1.0 GATEDSK:800 (squid/2.6.STABLE13)
X-Cache MISS from GATEDSK
X-Pad avoid browser bug

When I try to download through the script
(Status-Line) HTTP/1.0 200 OK
Connection close
Content-Disposition attachment; filename="test.zip"
Content-Encoding gzip
Content-Transfer-Encoding binary
Content-Type application/x-download
Date Sat, 17 Nov 2007 09:59:37 GMT
Expires 0
Pragma public
Server Apache/2.2.3
Vary Accept-Encoding
Via 1.0 GATEDSK:800 (squid/2.6.STABLE13)
X-Cache MISS from GATEDSK

In the script I've tried indicating content-length or not, but it's the
same. I've also added "Pragma: public" while I've read it was required
by IE, but not any evolution).

However, searching Google, I've seen this IE behavior is largely a
problem for a lot of people... But I don't see any clear solution until
now... I continue
 
Reply With Quote
 
Us
Guest
Posts: n/a
 
      11-17-2007
In article <fhmujv$2i09$(E-Mail Removed)>, (E-Mail Removed) says...
> This work for me
>


Interesting, because it doesn't work on my side (I've tried under
Windows too, to be on same case as yours).

I've tried a first time with the path with c:\... as you, and a second
time changing to something in the web space like this (w/o some typo
found) :

#!/usr/bin/perl
use strict;
my $file='../../htdocs/test/test.zip';
my $name=$file;
$name=~s/^.+\/(.+)$/$1/;
my $size=(stat $file)[7];
binmode STDOUT;
print "Content-Type: application/zip\n",
"Accept-Ranges: bytes\n",
"Cache-Control: no-cache, no-store, no-transform, must-revalidate\n",
"Content-disposition: attachment; filename=$name\n",
"Content-Length: $size\n\n";
my $buf;
open(F,"<$file");
binmode F;
read(F,$buf, 1024);
while ($buf)
{
print $buf;
read(F,$buf, 1024);
}
close F;

And it continue do do the same : IE start download-dlg, then search for
info and sto with an error saying "Internet Explorer cannot download
download_test.pl from www.mysite..."

I've tried with a lot of HTTP headers now and not any solution
 
Reply With Quote
 
Us
Guest
Posts: n/a
 
      11-18-2007
In article <(E-Mail Removed)>, (E-Mail Removed)
says...
> I've tried with a lot of HTTP headers now and not any solution
>


Continuing, I've found something ; even if it's not about Perl, it may
interest some.

Searching, I've finally found an HTTP header which works under a local
Apache/Windows :

print "Content-Type: application/octet-stream\n";
print "Content-Length: $size\n";
print "Content-Disposition: attachment; filename=$file\n";
print "Pragma: public\n";
print "Cache-Control: must-revalidate, post-check=0, pre-check=0\n";
print "Expires: 0\n\n";

The problem is that it still didn't work under remote Apache/FreeBSD. IE
fails to find info about file, then display an error.

Searching again and again, I've found an MS article at
http://support.microsoft.com/default...b;en-us;812935 talking
about ""Internet Explorer Cannot Download" Error Message When You Use an
HTTPS URL to Open an Office Document or PDF File".

Well, in my case, it's not an HTTPS url and not about PDF/DOC/XLS/MDB
document... But, I've tried what they say :

********
Article ID : 812935
Last Review : November 15, 2007
Revision : 2.5

CAUSE
This issue may occur if any one or more of the following conditions are
true: ? The Do not save encrypted pages to disk check box is selected in
Internet Explorer 6.0 SP1.
? The server sends the "Cache-Control: No Store" header.
? The server sends the "Cache-Control: No Cache" header.

RESOLUTION
A supported hotfix is now available from Microsoft. [they don't give any
url for doanload]

WORKAROUND
To work around this problem, make sure that Do Not Save Encrypted Files
check box is not checked and that the server does not send the "Cache-
Control: No Store" or the "Cache-Control: No Cache" header.

You may also be able to work around this problem by using an HREF to
load the document.

Note This method does not work if the server uses the "Cache-Control: No
Cache" header.
**********


Thus, I've unchecked the "Do Not Save Encrypted Files" IE's check box in
its options... And magically, it works !

Good for me, but wrong for my visitors if they have this case checked.
How to manage this IE6 Bug according to you ???
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
When I turn on my PC, it works, works, works. Problem! Fogar Computer Information 1 01-17-2006 12:57 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM
import of 'string' fails in CGI-BIN script...but works in IDLE John F Dutcher Python 0 12-02-2003 06:40 PM
Inline script works - but fails when included from .js file - why? Randell D. Javascript 7 10-26-2003 07:04 PM



Advertisments