chmod permission help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

chmod permission help

Post by Addos »

Hi.
I need to set permissions on files that I upload with the script below. I’m trying to implement chmod ($clean, 0600); but really don’t know where to add this as I’m getting the usual errors “No such file or directory” & “Unable to move” etc.

This works without chmod

Code: Select all

$source = $_FILES['fupload']['tmp_name'];
    $target = "snail/attach/" .$_FILES['fupload']['name'];
 
    /* Clean up spaces strip html tags white space make lowercase. */
        $clean = strip_tags(trim(strtolower($target)));
        
    //strip spaces
        $clean = str_replace(' ' , '_' , $clean);
        
           move_uploaded_file( $source, $clean ); // or die ("coultn't copy");
           echo '<br><strong> File'. $clean . ' ' . 'was successfully Uploaded.</strong>'; 
            
            }
I have tried a few variants such as

Code: Select all

move_uploaded_file( $source (chmod ($clean, 0600) ));
or

Code: Select all

$clean = str_replace(' ' , '_' , $clean);
        $setper=chmod ($clean, 0600);
           move_uploaded_file( $source, $clean ); // or die ("coultn't copy");
           echo '<br><strong> File'. $setper . ' ' . 'was successfully Uploaded.</strong>';
but obviously these are incorrect. Any help would be great
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: chmod permission help

Post by jackpf »

Umm...just a guess, but don't you want to chmod the file after you've uploaded/moved it?
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: chmod permission help

Post by Ollie Saunders »

You need to change the permissions of the directory you are moving the uploaded file to. You can probably do this with your FTP client instead of doing it in your script.
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: chmod permission help

Post by Addos »

Thanks Guys,
I just sorted this as I wasn't sure about how it all worked and it 'was' that I needed to change the permissions after I uploaded the file.
Thanks for the great help.
Post Reply