Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load the file then change permissions

Status
Not open for further replies.

stiffler

Programmer
Aug 15, 2000
3
US
Hey All

Great forum, I have honestly found most answers by searching old posts, except this one:

I have .pdf files which I keep chmod 600 for security reasons on my server. Although I want people who authenticate (.htaccess) to get access to these files, so what I want to happen is the following:

chmod (644, "file.pdf");
print "Location: file.pdf\n\n";
chmod (600, "file.pdf");


Although I noticed the reality is that the 2nd chmod happens too fast for the file to load. How can I load the file and print it to the screen once it has loaded then chmod it back to 600, but please realize this is not a normal .html file but a .pdf???

Any and every suggestion would be great!!!!

 
Hi stiffler,

(1) you could use the sleep function before the second chmod

or

(2) open the file (in bin mode) print it to the
webserver then chmod it back.

hope this helps

 
Hey Ken

I tried sleep and it didn't work very nicely at all, but can you give me an example of how to accomplish your (2) suggestion?

Thanks
 
I haven't tested this but it "should work"
happy.gif
.
Let use a jpeg file for example.
---- view_pic.cgi ---
# open the image
# change the permissions
open (IMAGE,"$filename") || die "can't open $filename";

# I think this is the correct content-type ... get'n late
# need sleep.
print "Content-type: image/jpeg"; # let server know what's
# com'n.

while (<IMAGE>){
# start reading and writing to the webserver

print $_;
};
close (IMAGE);

# chmod back.

------------ end script ----------
example usage :
<img src=&quot;view_pic.cgi&quot;>

Hope this gives you some ideas

Cheers
 
Only problem with that is that is doesn't determine the size of the pdf, for instance if the pdf is 2MB versus 50KB, any other workarounds??

thanks
JK
 
Hi JK,

Use the -s $filename option. This will check if the
file has nonzero size and returns the size of the file.

cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top