Solved

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

Posted on 2007-11-30
3
859 Views
Last Modified: 2010-04-21
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

0
Comment
Question by:sivle
  • 2
3 Comments
 
LVL 20

Accepted Solution

by:
steelseth12 earned 250 total points
ID: 20385255
just use

chmod("path/to/uploaded/image/image.ext",0777);

you need to put the leading 0 in front of the permission
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 20385259
0
 

Author Closing Comment

by:sivle
ID: 31412031
Thanks, that's what i needed.

sivlE
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question