Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

load the file then change permissions

load the file then change permissions

load the file then change permissions

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!!!!

RE: load the file then change permissions

Hi stiffler,

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


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

hope this helps

MySQL Webring

RE: load the file then change permissions

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?


RE: load the file then change permissions

I haven't tested this but it "should work" .
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="view_pic.cgi">

Hope this gives you some ideas


MySQL Webring

RE: load the file then change permissions

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??


RE: load the file then change permissions

Hi JK,

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


MySQL Webring

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close