Hi Andy,

I'll give it a try and let you know. I just tried the current version of the script (the one that IE Mac has a problem with) on a PC and it works great. So it seems to just be IE Mac. So I'll try the new thing and let you know.

Thanks,

Mark

On Aug 25, 2004, at 5:47 AM, Andrew Mace wrote:

IE just displays the graphic but doesn't download it. The script does not seem to be overriding whatever the settings are in IE regarding MIME types and what to do with them -- I'm guessing. Is there a way to override that?

You could try changing the Content-Type to application/download. The problem is Mac IE will show the save as prompt, but it will be the name of your script (download.pl) and not the filename you specified in the HTTP header. I haven't found any workaround for this. When I've done things like this in the past I've ended up using Apache conf settings like Chris' suggestion, though I'm realizing as I'm writing this that using $ENV{PATH_INFO} instead of the query string might solve that problem - take a look at the other Andy's suggestion for how to use that:


<a href="javascript:window.location='cgi-bin/download.cgi/Upload- Background.gif'">picture link</a>

my $filename = $ENV{'PATH_INFO'};


Good luck
Andy




On Aug 24, 2004, at 6:17 PM, Andrew Mace wrote:


$path is a system path, right? As in, like, not relative to the webserver? Just making sure...


Also, I messed up and used $length in one place and $size in another, though that doesn't explain your troubles.

I mean, you could do a lot of things to debug. A quick thing you could do would be to change the content type to image/jpeg and remove the Content-Disposition and see what gets put into your browser. Since you're writing the HTTP headers before attempting to open the file, my suspicion is that there's something wrong with the path to the file and your script is exiting prematurely.

Andy





On Aug 24, 2004, at 8:23 PM, Mark Wheeler wrote:

Hi Andy,

Thanks for the input. I should have check the "read/write" method -- my bad.

I tried both the slurp and the read methods, but the same thing still happens. On a PC the save dialog comes up but the file saved is 0k, and on a Mac, the the progress bar is just a spinning barber poll. Any ideas?

Thanks,

Mark

On Aug 24, 2004, at 3:56 PM, Andrew Mace wrote:

Hey Mark -

A few things.
- You want to open the file for reading, not to write.
- You should undef $/ to slurp the file if you're using < > to read.
- You should stat the file before opening it to add the Content-Length header, if you want.
- For larger files, it would make more sense to use read() calls instead of slurping the entire file into memory.


So here's an updated version:

#!/usr/bin/perl -w

use strict;
use CGI ':standard';

my $filename = param('picname');
my $path = "/images/$filename";
my $length = (stat($path))[7]; # the size, in bytes
binmode STDOUT;

print "Content-Length: $size\n";
print "Content-Disposition: attachment;filename=$filename\n";
print "Content-Type: application/octet-stream\n\n";

open (FILE, "< $path") || die("Can't open($filename): $!");
binmode(FILE);

# slurp method:
undef $/;
my $data = <FILE>;
close (FILE);
print $data;

# read() method would be:
while(read(FILE,$data,4096)) {
        print $data;
}
close(FILE);

exit;


Good luck Andy



On Aug 24, 2004, at 6:19 PM, Mark Wheeler wrote:

Hi all,

Here is my first attempt to write this script. I will be adding the protection/whitelisting/etc. after I get the basic this running. Here is what I have so far, and here is what happens. On a PC, the dialog box comes up and saves the file, but it is 0K -- nothing in it. On a Mac, the "Downloads" dialog box comes up, but the progress bar keeps spinning and nothing happens. Below is the HTML that calls the script and the CGI script itself. What did I forget/do wrong?

Thanks,

Mark

-------------------------------------------------------------

<html>
<head>
<title>Untitled Page</title>
</head>
<body>
<a href="javascript:window.location='cgi-bin/download.cgi? picname=Upload-Background.gif'">picture link</a>
</body>
</html>


-------------------------------------------------------------

#!/usr/bin/perl -w

use strict;
use CGI ':standard';

my $filename = param('picname');
my $path = "/images/$filename";

binmode STDOUT;
print "Content-Disposition: attachment;filename=$filename\n";
print "Content-Type: application/octet-stream\n\n";

open (FILE, "> $path") || die("Can't open($filename): $!");
my $data = <FILE>;
close (FILE);

print $data;

exit;

---------------------------------------------------------


On Aug 23, 2004, at 2:45 PM, Joel Rees wrote:

I think that's what I'm looking for. One question. What do you mean "whitelist" the filepaths". My only reference point is email. "Whitelist" for me means that email address on my "whitelist" always get through, even though the spam software might initially think it's spam. Can you clarify?

If the script I posted was readable, you might have noticed that it accepts one parameter and sets the directories only if that parameter matches correctly. It looks like a waste, but it's one way of what he was calling whitelisting in a fairly strict way, but allowing the same script to be used on multiple sets of images. You do have to add a little code for each set of images, of course.


That script needs some comments.

--
Joel Rees
Getting involved in the neighbor's family squabbles is dangerous.
But if the abusive partner has a habit of shooting through his/her roof,
the guy who lives upstairs is in a bit of a catch-22.










Reply via email to