Link to home
Start Free TrialLog in
Avatar of sivle
sivle

asked on

Using chmod with PHP to change file permissions after/during upload of images

OK...not sure if i'm providing enough information or not, but hopefully someone can help me. When I upload images to a directory, the default permissions are set to 600 on the files themselves. The directory has 777 permissions. I want to make my images readable and give them either 666 or 644 permisssion. Either would work. I suppose I need to somehow chmod the image files during upload or just after. Here is my code snippet that handles the image upload. I'm just not sure how to implement the needed change.

/***start****/
if ( $_FILES['bgimg']['name'] && !$_POST['bgdel'] )
    {

          if ( strlen($custom_arr['BackgroundFilename']) && file_exists($dir['profileBackground'] . $custom_arr['BackgroundFilename']) && is_file($dir['profileBackground'] . $custom_arr['BackgroundFilename']) )
              @unlink($dir['profileBackground'] . $custom_arr['BackgroundFilename']);

      srand(time());
      $pic_name = $ID . '_bg_' . rand(100, 999);
      
                  if ( !is_int($ext = moveUploadedImage( $_FILES, 'bgimg', $dir['profileBackground'] . $pic_name, '',false) ) )
                  
                  {
                  
                      if ( !$record_created )
                      {
                          $query = "INSERT INTO ProfilesSettings (`IDMember`, `BackgroundFilename` ) VALUES ( '$ID', '$pic_name$ext' )";
                              $record_created = 'ok';
                      }
                      else
                      {
                          $query = "UPDATE ProfilesSettings SET `BackgroundFilename` = '$pic_name$ext', `Status` = 'Approval' WHERE `IDMember` = '$ID'";
                        }
                      $res = db_res( $query );

                  }

    }
    else if ( $_POST['bgdel'] )
    {

        if ( $custom_arr['BackgroundFilename'] )
            {
                if (file_exists($dir['profileBackground'] . $custom_arr['BackgroundFilename'])) unlink($dir['profileBackground'] . $custom_arr['BackgroundFilename']);

                      $query = "UPDATE ProfilesSettings SET `BackgroundFilename` = '' WHERE `IDMember` = '$ID'";
                      $res = db_res( $query );
                  }

    }

/**** end ****/

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of steelseth12
steelseth12
Flag of Cyprus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sivle
sivle

ASKER

Thanks, that's what i needed.

sivlE