Results 1 to 4 of 4

Thread: Setting file permissions

  1. #1
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default Setting file permissions

    I'm using a script that re sizes and uploads pictures to a directory in my website. The script seems to be working fine, but when I try to view the uploaded pictures I'm getting a 403 forbidden error. I contacted my hosting provider and they told me that the permissions need to be changed in the script using chmod.... I did a little research and found a way to do this using php but I'm not quite sure how to combine the scripts together.. I was wondering if some one could help me out here.
    Code:
    <?
    set_time_limit ( 240 ) ;
    
    $target_path = "uploads/";
    
    $target_path = $target_path . basename( $_FILES['Filedata']['name']);
    $orig=$target_path;
    $info = pathinfo($target_path);
    
    $ctr=1; 
    while(file_exists($target_path)){
    	$target_path=$info['dirname']."/".$info['filename'].$ctr.".".$info['extension'];
    	$ctr++;
    
    }
    
    if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path)) {
        echo "status=1&filepath=$target_path&size=".$_FILES['Filedata']['size'];
    
    
    } else{
        echo "status=0&msg=Error";
    }
    
    
    
    ?>
    Here is the chmod setting I think I need?

    Code:
    <?
    chmod("upoads/somefile", 0755);
    
    
    ////where do I put this and what should go where (somefile) is?
    ?>
    Thanks in advance

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You wanna do that right after you've uploaded the file, so like this:

    PHP Code:
    if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path)) {
        echo 
    "status=1&filepath=$target_path&size=".$_FILES['Filedata']['size'];

            if(!
    chmod($target_path0755))
                echo 
    "status=0&msg=Error";
            
    } else{
        echo 
    "status=0&msg=Error";


  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    captainjustin (12-11-2010)

  4. #3
    Join Date
    Aug 2009
    Location
    Florida
    Posts
    23
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default That fixed it.

    Thank you so much!!!!! That worked like a charm. You have made my day!

  5. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    My recommendation is always adding a chmod command after creating any new file automatically. This solves problems (avoids them actually) that you might find later. For example, it might be visible by HTTP but not to your FTP user-- this has happened to me a few times.
    Using the same basic approach, just always add this line:
    chmod($file,0755);
    That way nothing unpredictable happens.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •