in reply to Setting file upload permissions

The script that handles your image upload has to call the chmod function on the uploaded file.

See perldoc chmod.

$cnt = chmod 0755, 'foo', 'bar'; chmod 0755, @executables; $mode = '0644'; chmod $mode, 'foo'; # !!! sets mode to # --w----r-T $mode = '0644'; chmod oct($mode), 'foo'; # this is better $mode = 0644; chmod $mode, 'foo'; # this is best

Replies are listed 'Best First'.
Re: Re: Setting file upload permissions
by sulfericacid (Deacon) on Apr 18, 2003 at 06:51 UTC
    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

      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