Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Re: Re: Re: Re: Serving files without revealing their location

by Fastolfe (Vicar)
on Jan 29, 2001 at 02:58 UTC ( [id://54916]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: Serving files without revealing their location
in thread Serving files without revealing their location

Ah, I guess this makes a little more sense.

Still, I might suggest that you use HTTP authentication to do something like that. That way you can use the same standard URL, but allow the HTTP authentication to determine who gets access to it.

Saving that, it looks like the technique you describe should work for you. I might extend it to put the filename in the "path_info" variable for your script.

use CGI ':standard'; use File::Spec 'rel2abs'; my $base = '/www'; my $filename = rel2abs(path_info, $base); if ($filename =~ /^\Q$base/ && open(F, "< $filename\0") && -f F) { print "Content-type: application/pdf\n"; # or whatever print "Content-length: ", -s F, "\n\n"; print while <F>; close(F); } else { # handle errors, perhaps do a Status: 403 or 404 # along with a nice description, using $! if you want }
Then you can call your script like this:
http://www.example.com/cgi-bin/script.pl/path/filename.pdf
Which will end up retrieving /www/path/filename.pdf, if it exists. Otherwise presumably you'd want to send a 404 status, for example. This would allow you to use "real"-looking URL's while pumping it through your CGI anyway.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://54916]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-20 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found