in reply to Re: Setting file upload permissions
in thread Setting file upload permissions

Ok, thanks for the link. I think I understand how the syntax of chmoding works but I can't seem to implement it into my snippet. The files still upload at a very limited access. Any ideas? Thanks for the link, that was very helpful!
$mode = 0644; # take form data my $remotefile = param('upload'); # make new variable to prevent overwriting of form data my $filename = $remotefile; # remove all directories in the file name path $filename =~ s/^.*[\\\/]//; # full file path to upload directory (must include filename) my $localfile = "/home/sulfericacid/public_html/upload/files/$filename +"; # open a new file and transfer bit by bit from what's in the buffer open (SAVED,">>$localfile") || die $!; while ($bytesread=read($remotefile,$buffer,1024)) { chmod $mode, '$filename'; print SAVED $buffer; } close SAVED;


"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

Replies are listed 'Best First'.
Re: Re: Re: Setting file upload permissions
by Heidegger (Hermit) on Apr 18, 2003 at 07:05 UTC

    You should call the chmod function after file write to the disk:

    # open a new file and transfer bit by bit from what's in the buffer open (SAVED,">>$localfile") || die $!; while ($bytesread=read($remotefile,$buffer,1024)) { print SAVED $buffer; } close SAVED; chmod $mode, '$filename';

    Hope this should work ;-)

      I tried adding chmod before, after and during saving and it didn't change the attributes. Does anyone else have any ideas? Thanks for your help!

      "Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

      sulfericacid
        chmod'ing before you save only works if the file already exists, duing the save makes no sense at all. After is really what you should be doing. But ... you are missing something ... always check to see if the operation worked:
        chmod $mode, '$filename' or die "can't chmod: $!";
        I'll wager my money that a user other than the one that your web server runs as (prolly you) owns that file or the directory that will contain that file. Make sure you first manually chown -R that directory to the user that your web server runs as first. You can find out who that user is with a quick:
        
        grep ^User /path/to/apache/conf/httpd.conf
        
        on a *NIX command line.

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)