Page 1 of 1

chmod permission help

Posted: Mon Sep 14, 2009 6:23 am
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

Re: chmod permission help

Posted: Mon Sep 14, 2009 7:31 am
by jackpf
Umm...just a guess, but don't you want to chmod the file after you've uploaded/moved it?

Re: chmod permission help

Posted: Mon Sep 14, 2009 11:55 am
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.

Re: chmod permission help

Posted: Mon Sep 14, 2009 12:15 pm
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.