Solved

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

Posted on 2007-11-30
3
857 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
Comment Utility
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
Comment Utility
0
 

Author Closing Comment

by:sivle
Comment Utility
Thanks, that's what i needed.

sivlE
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now