Fastest way to send file to browser

H

howa

In order to hidden the real path, I send the png file via CGI, e.g.

##############

print "Content-type:image/png\n\n";
my $file = "test.png";

open INPUT_FILE, "$file" or die "Couldn't open file: $!";
while( sysread(INPUT_FILE, $data, 10240) ) {
print $data;
}
close FILE;

##############

Any faster/better method?

Thanks.
 
X

xhoster

howa said:
In order to hidden the real path, I send the png file via CGI, e.g.

##############

print "Content-type:image/png\n\n";
my $file = "test.png";

open INPUT_FILE, "$file" or die "Couldn't open file: $!";
while( sysread(INPUT_FILE, $data, 10240) ) {
print $data;
}
close FILE;

##############

Any faster/better method?

Take a step back and do some introspection on why you want to hide the
real path in the first place.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
H

howa

Take a step back and do some introspection on why you want to hide the
real path in the first place.

Xho

An example would be captcha images, good reason?

Thanks.

Howard
 
H

howa

howa said:
In order to hidden the real path, I send the png file via CGI, e.g.
[Perl program]
Any faster/better method?

An alias (HTTP server directive).

Hi,

A path is mapped to many files, so the real file is only know when
client request for the page.

I have heard something like x-sendfile but we don't have this option
to use, so I must send thru perl.

Thanks.

Howard
 
X

xhoster

howa said:
An example would be captcha images, good reason?

Probably not. I would expect captcha images to be either generated on the
fly or stored in a database, so there is no path to hide. Or selected on
the fly, in which case your goal is not to hide the path but to select the
path.

Given that you are going to start up Perl in the first place, I don't
see any obvious problems with our code, other than possibly a lack of
error checking on the sysread. And that the file handle you close
is different than the file handle you open.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
H

howa

Probably not. I would expect captcha images to be either generated on the
fly or stored in a database, so there is no path to hide. Or selected on
the fly, in which case your goal is not to hide the path but to select the
path.

I have cron job to generate the images from time to time, as real time
is expensive for server.
We also put the image file outside the document root, so we must send
the file using Perl.
Given that you are going to start up Perl in the first place, I don't
see any obvious problems with our code, other than possibly a lack of
error checking on the sysread. And that the file handle you close
is different than the file handle you open.

Thank you .

Howard
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top