Solved

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

Posted on 2007-11-30
3
860 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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 is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

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