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