SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Notre Dame, IN
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with uploading images (permissions)

    Hi, first time posting (sorry if the code isn't highlighted right, though I think I got it). I'm relatively new to php and web design in general, so I might just be doing something stupid. I wrote this function (its based on Kevin Yank's book) to upload user pictures for my counter-strike clans web site. I keep getting an error about permissions, and I don't think that it is related to chmod as I've given read, write and execute permission to the folder I want to store the picture in (and all the folders above it). I know that the server where we're hosting the site is running php safe mode. I kinda thought that this might be the problem, though I'm really not sure. I'd really appreciate any help you guys could give if it is the safe mode is there a work around of some sort. I was thinking of saving the images in the mysql table itself, but was afraid it would be a problem with load speed. Oh I almost forgot, the error refers to the line that uses the copy() function.

    PHP Code:
    function upload_picture() {
            global 
    $picture$picture_type$handle;
        
            if (
    $picture_type == "image/pjpeg" || $picture_type == "image/gif") {
                
                if (
    $picture_type == "image/pjpeg") {
                    
    $extension ".jpg";
                } else {
                    
    $extension ".gif";
                }

                
    $handle rawurlencode($handle);
                
    $filename "./images/userpics/$handle$extension";
                
                if (!
    copy($picture$filename)) {
                    echo 
    "Unable to upload the picture.  Press the back button on your browser to try again.";
                    exit;
                }

            } else {
                echo 
    "Please submit a .jpg or a .gif image.  Press the back button on your browser to try again.";
                exit;
            }
        } 

  2. #2
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, you might want to either set the folder to chmod 0777 or create the folder with php, check out mkdir() function in php.
    Then if you want to create folder
    .../user/dir/
    you would start with setting /user/ to 0777, create the folder with php and then set the /user/ back to 0744.

    Hope that helps...
    - website

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2003
    Location
    Notre Dame, IN
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help, but it still doesn't seem to be working. Is there anything wrong with the actual code? Or is it some issue with permissions on the server.

  4. #4
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm, what is $picture, is it the path to the temporary location ?

    And isn't 'image/pjpeg' supposed to be 'image/jpeg' ?
    - website

  5. #5
    SitePoint Member
    Join Date
    May 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've got a similar case. I used the following code to change the properties of a folder so that I can upload pictures to that folder:

    chmod ($DestinationFolder, 0755);

    but when it is running, the error appears as follows:

    Warning: chmod() [function.chmod]: Operation not permitted in [filename].php on line 78

    Please help me to correct it.

  6. #6
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, then I would belive PHP didn't create the folder so it doesn't have access to modify it's permissions.

    And then again php might not have access to create folder in the folder where the folder is so you would have to change the permission in the folder where the folder is to 0777 while creating the folder and then place it back to 0744 ...

    confusing ?
    Just woke up, that might explain
    - website

  7. #7
    SitePoint Member
    Join Date
    May 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you mean I can set 0777 to a folder only when it is created by mkdir? And I cannot change mode for an existing folder?

  8. #8
    ********* Member website's Avatar
    Join Date
    Oct 2002
    Location
    Iceland
    Posts
    1,238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes

    because PHP is not the 'creator' of the folder, only the program that created the folder can modify it's options (usually...)
    - website


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •