Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

864 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

19 Experts available now in Live!

Get 1:1 Help Now