Perl and Internet Explorer

A

akaliel

Hi everyone, I'm having a problem with cgi perl scripts. We have a
perl based Intranet that contains mostly pdf documents. When a user
wants to view a file they simply click on a link and a perl script
figures out which file they want to view and streams it to their
browser. It works just fine for PDF's. The Acrobat plugin launches
and loads the file. However, we also have Powerpoint files on the
Intranet as well. These do not behave properly. What happens is the
Open/Save dialog comes up. If you click Save then it tries to save it
as a .pl file. If you click open Windows uses whatever program is set
in File Types to open .pl files (usually Notepad).

The only solution seems to be if you click Save and then manually
change the extension from .pl to .ppt. Which isn't a problem for me,
but the less computer savvy people around here can't handle it.

There aren't any problems in Netscape. It defaults the extension to
..ppt and clicking Open instead of Save launches Powerpoint correctly.
I know that Netscape works because it reads the MIME type correctly
(application/ppt), and IE doesn't work b/c in Microsoft's infinite
wisdom, they've programmed IE to ignore MIME types.

So I've deduced these as my options. I either need a Powerpoint
plugin that goes into the "Internet Explorer/plugin" directory, much
like that of Acrobat. Figure out how to get IE to READ my MIME types.
Or use some backhanded method to default the IE extension to .ppt for
Powerpoint files.

Note that I cannot simply rename my perl script to be .ppt instead of
..pl because then it wouldn't run at all. It has to be .pl.

Much help would be very appreciated. Thanks very much,

Allan
 
J

Joe Smith

akaliel said:
The only solution seems to be if you click Save and then manually
change the extension from .pl to .ppt. Which isn't a problem for me,
but the less computer savvy people around here can't handle it.

HTML: Download <A HREF="/cgi-bin/select-file.pl/1.ppt">Project 1</A>.
CGI: Check $ENV{PATH_INFO} if no $ENV{QUERY_STRING}.
-Joe
 
M

Matt Garrish

akaliel said:
Hi everyone, I'm having a problem with cgi perl scripts. We have a
perl based Intranet that contains mostly pdf documents. When a user
wants to view a file they simply click on a link and a perl script
figures out which file they want to view and streams it to their
browser.

Any reason why you need to "stream" the files to the browser instead of
simply redirecting to the resource? Or is it just a case of that's the way
the script works?

Matt
 
G

gnari

[snip IE problem]

use the $ENV{PATH_INFO} trick if your webserver supports it,
or just drop IE. there are plenty of alternatives

gnari
 
A

akaliel

Matt Garrish said:
Any reason why you need to "stream" the files to the browser instead of
simply redirecting to the resource? Or is it just a case of that's the way
the script works?

Matt

They have to stream because that's the way the script has to work. I
can't redirect to the resource. Not unless I can convince my boss
that it's absolutely necessary, which, if you know the guy will
realize why that isn't likely to happen. The main reason he wanted
streaming n the first place is because he was paranoid about people
knowing the the directory structure of where files are stored on the
webserver.
 
A

akaliel

gnari said:
[snip IE problem]

use the $ENV{PATH_INFO} trick if your webserver supports it,
or just drop IE. there are plenty of alternatives

gnari

Heh, stupid me. My boss was actually searching for a solution at the
same time and came across my post. Doh! Busted!

Well, he explained to me why it's necessary to have files stream. It
makes sense. You see we have security in a database that gives
certain users permission to view certain links. If a person could
just be able to type in the filename they wished to see, then that
circumvents all our security. So that's why it needs to stream.

The PATH_INFO trick might work, I'll have to try it.

I actually did get it working half way. I got it so that if you right
click and select "Save Target As" then it will default to a .ppt file.
Though if you left click on the link, nothing happens. Absolutely
nothing at all.

Almost there. I'm convinced the solution lies in the registry. I'll
let you know if I find it.
 
M

Matt Garrish

akaliel said:
There aren't any problems in Netscape. It defaults the extension to
.ppt and clicking Open instead of Save launches Powerpoint correctly.
I know that Netscape works because it reads the MIME type correctly
(application/ppt), and IE doesn't work b/c in Microsoft's infinite
wisdom, they've programmed IE to ignore MIME types.

I didn't look closely at your MME type the first time. The correct type for
IIS should be:

application/vnd.ms-powerpoint

Not sure if it will make any difference to IE, but might be worth a try. And
if it does work but blows up Netscape you could always detect the browser
type and send the appropriate header.

Matt
 
A

akaliel

Not sure if it will make any difference to IE, but might be worth a try. And
if it does work but blows up Netscape you could always detect the browser
type and send the appropriate header.

Matt

That's the MIME type I'm using that managed to get it to partially
work. Right clicking on the link will allow me to save it as a .ppt
by default. However, left clicking on the link does nothing
whatsoever. If I right click and say "Open in New Window" then just
after the new window launches, it crashes.
 
M

Matt Garrish

akaliel said:
That's the MIME type I'm using that managed to get it to partially
work. Right clicking on the link will allow me to save it as a .ppt
by default. However, left clicking on the link does nothing
whatsoever. If I right click and say "Open in New Window" then just
after the new window launches, it crashes.

I assume you've already tried the following http header to specify a default
filename?

Content-Disposition: attachment; filename=[FILENAME]

If so, then I'm out of ideas...

Matt
 
A

akaliel

I assume you've already tried the following http header to specify a default
filename?

Content-Disposition: attachment; filename=[FILENAME]

If so, then I'm out of ideas...

Matt

Umm, no I hadn't. But I tried it and lo! It worked! More
specifically, I had to enter the following perl code to handle ppt and
exe files accordingly:

my $attachment;
if ($type_name eq 'PowerPoint Presentation') {
$attachment = "$filename.ppt";
}
elsif ($type_name eq 'EXE File') {
$attachment = "$filename.exe";
}
else {
$attachment = "";
}


print $q->header({-disposition=>'inline',
-type=>$header,
-attachment=>$attachment});

while (<FILE>) {
print $_;
}

close(FILE);
$| = 0; # turn on buffering of stdout

I'm going to clean it up a bit by actually having a mysql table handle
that bit of hardcoding I added that decides the proper extension for
the given file type. But it worked great. Thanks for all your help.

Allan
 
R

Richard Morse

Matt Garrish said:
akaliel said:
That's the MIME type I'm using that managed to get it to partially
work. Right clicking on the link will allow me to save it as a .ppt
by default. However, left clicking on the link does nothing
whatsoever. If I right click and say "Open in New Window" then just
after the new window launches, it crashes.

I assume you've already tried the following http header to specify a default
filename?

Content-Disposition: attachment; filename=[FILENAME]

You might try Content-Disposition: inline; filename=... instead -- this
may make the streaming work...

Ricky
 
M

Matt Garrish

Richard Morse said:
Matt Garrish said:
akaliel said:
Not sure if it will make any difference to IE, but might be worth a
try.
And
if it does work but blows up Netscape you could always detect the browser
type and send the appropriate header.

Matt

That's the MIME type I'm using that managed to get it to partially
work. Right clicking on the link will allow me to save it as a .ppt
by default. However, left clicking on the link does nothing
whatsoever. If I right click and say "Open in New Window" then just
after the new window launches, it crashes.

I assume you've already tried the following http header to specify a default
filename?

Content-Disposition: attachment; filename=[FILENAME]

You might try Content-Disposition: inline; filename=... instead -- this
may make the streaming work...

Good point. (From his reply, I think he figured it out on his own though.)

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,560
Members
45,035
Latest member
HoTaKeDai

Latest Threads

Top