Results 1 to 8 of 8

Thread: adding permissions

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default adding permissions

    How can I set the permissions of images that are being uploaded from the site itself? I tried chmod last week but using that I did not have permissions on it from the ftp which I still want to be able to do. I think I had chmod ( name , 0777). I want the images to be 777 right now they are uploading as 600 and aren't displayable (403 forbidden) without going threw the ftp and changing it
    This is the php I'm using.
    PHP Code:
    //increase the number of files uploaded
    $counterfile "number.txt";
    $fp fopen($counterfile,"r");
    $hits fgets($fp,100);
    fclose($fp);
    $hits++;
    $myFile "uploads.txt";
    $fp fopen($counterfile,"w");
    fputs($fp$hits);
    fclose($fp);
      
    $success 0;
      
    $fail 0;
      
    $uploaddir 'uploads/';
      for (
    $i=0;$i<3;$i++)
      {
       if(
    $_FILES['userfile']['name'][$i])
       {
        
    $uploadfile $uploaddir basename($_FILES['userfile']['name'][$i]);
        
    $ext strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
        if (
    preg_match("/(jpg|gif|png|bmp)/",$ext))
        {
         if (
    move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile))
         {
          
    $success++;
         }
         else
         {
         echo 
    "Error Uploading the file. Retry after sometime.\n";
         
    $fail++;
         }
        }
        else
        {
         
    $fail++;
        }
       }
      }
      echo 
    "<br> Number of files Uploaded:".$success;
      echo 
    "<br> Number of files Failed:".$fail;


  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Can you send us the code you tried when you tried using chmod?
    Jeremy | jfein.net

  3. #3
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I didnt try it with this code and I deleted it from the last because I didnt know why it was doing what it was doing last time. I thought chmod was something that would do the same thing everytime. This is what my service provider told me last time ...

    Our PHP works as apache module. And httpd is apache user. So all files and folders that were created or changed by apache would have httpd as owner. To restore your default owner you should enter your control panel->FTP service->Enable FTP for one of your domain (if you have all turned off)->click edit button and add virtual ftp directory where you have wrong owner for your files. For example yourdomain.com/ After this you will be able to change or delete this files.
    If you could tell me how to use the chmod to avoid this I'll try it again. I wasnt sure if it was the chmod or the mkdir that did it but I was using both and then this happened.

  4. #4
    Join Date
    Mar 2008
    Posts
    122
    Thanks
    17
    Thanked 5 Times in 5 Posts

    Default

    have you tried to chown function?

  5. #5
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    No, what is $user_name? I don't understand the root term. I've had to switch the permission each time in the ftp to 777 from 600. Would 700 go in place of root???

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I've gone back to the chmod since 9/10 say that but its not working this way still. I still do not get the chown If anyone could explain that or thinks it would work better? Thanks. This does not create any errors and puts the file up but does not change the permissions still (600 should be 777).
    PHP Code:
    //increase the number of files uploaded
      
    $success 0;
      
    $fail 0;
      
    $uploaddir 'uploads/';
      for (
    $i=0;$i<3;$i++)
      {
       if(
    $_FILES['userfile']['name'][$i])
       {
        
    $uploadfile $uploaddir $name $age $denim $lifestyle basename($_FILES['userfile']['name'][$i]);
    chmod($uploadfile 0777); // THIS LINE IS THE NEW ONE
        
    $ext strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
        if (
    preg_match("/(jpg|gif|png|bmp)/",$ext))
        {
         if (
    move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile))
         {
          
    $success++;
         }
         else
         {
         echo 
    "Error Uploading the file. Retry after sometime.\n";
         
    $fail++;
         }
        }
        else
        {
         
    $fail++;
        }
       }
      }
      echo 
    '<div style="margin-top:210px" text-align:center;>';
      echo 
    "<br> Number of files Uploaded:".$success;
      echo 
    "<br> Number of files Failed:".$fail;
      echo 
    '</div>';


    EDIT
    I also found this, here (http://www.phpbuilder.com/board/show...php?t=10314483) which sounded like my problem by still doesn't work. The new if statement here just loads the page blank.

    PHP Code:
    //increase the number of files uploaded
      
    $success 0;
      
    $fail 0;
      
    $uploaddir 'uploads/';
      for (
    $i=0;$i<3;$i++)
      {
       if(
    $_FILES['userfile']['name'][$i])
       {
        
    $uploadfile $uploaddir $name $age $denim $lifestyle basename($_FILES['userfile']['name'][$i]);
        
    $perms substr(sprintf('%o'fileperms($uploadfile)), -4); //THE WHOLE NEW STATEMENT STARTS HERE
          
    if($perms !== '0777')
          {
             if(
    chmod($uploadfile0777)===TRUE)
             {
                echo 
    'Changed permissions of file successfully.<br>';
             }
             else
             {
                 echo 
    'Failed to change permissions of file.<br>';
             } 
    //ENDS HERE
     //  chmod($uploadfile , 0777); // THIS IS THE LINE FROM ABOVE THAT ALSO DIDNT WORK BUT APPEARED CLOSER ( NO BLANK PAGE)
        
    $ext strtolower(substr($uploadfile,strlen($uploadfile)-3,3));
        if (
    preg_match("/(jpg|gif|png|bmp)/",$ext))
        {
         if (
    move_uploaded_file($_FILES['userfile']['tmp_name'][$i], $uploadfile))
         {
          
    $success++;
         }
         else
         {
         echo 
    "Error Uploading the file. Retry after sometime.\n";
         
    $fail++;
         }
        }
        else
        {
         
    $fail++;
        }
       }
      }
      echo 
    '<div style="margin-top:210px" text-align:center;>';
      echo 
    "<br /> Number of files Uploaded:".$success;
      echo 
    "<br /> Number of files Failed:".$fail;
      echo 
    '</div>';

    Last edited by bluewalrus; 12-26-2008 at 05:11 AM.

  7. #7
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Does anyone know where I can find other functions for swapping the permissions or any tutorials that relate to it? I've been here and tried this http://us3.php.net/chmod as well as the link above but still with no luck and the chown.

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Solution (put on the gallery display page not on the upload page itself)...(it won't let me change to resolved)
    PHP Code:
    <?php
    $dir 
    '/uploads/';
    $d dir($dir);
    while(
    FALSE !== ($entry $d->read()))
    {
       if(
    $entry != '.' && $entry != '..')
       {
          
    // get the file permissions
          
    $perms substr(sprintf('%o'fileperms($dir.$entry)), -4);
          if(
    $perms !== '0755')
          {
             if(
    chmod($dir.$entry0755)===TRUE)
             {
             
    //WORKED DID CHANGE
             
    }
             else
             {
             
    //ERROR DIDN'T CHANGE
             
    }
          }      
       }
    }
    ?>

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
  •