Problem with upload script and CHMOD's

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • petershaman
    New Member
    • Nov 2008
    • 3

    Problem with upload script and CHMOD's

    Hi
    I have a gorgeous flash image gallery, it would work perfectly fine but there's a small problem I can't upload anything thru it's upload script, since I'm getting an error 403. It's so because server sets by default CHMOD 600, whilst gallery needs to be set 644 to operate correctly.

    In this upload php script there is a command which theoretically should change permissions for uploaded files, but it's not doing the job, there's obviously some bug over there, and here's my question, could you be so kind and take a glimpse at this code, and tell me how to shrink it? Cheers

    [PHP]
    /**
    * Upload file
    *
    */
    function uploadAction()
    {
    $this->_setNoRender() ;
    if (!isset($_FILES['Filedata'])) {
    header("HTTP/1.1 500 Internal Server Error");
    echo "Error. File not found";
    return;
    }
    $imageData = $_FILES['Filedata'];
    if (!ivFilepath::m atchSuffix($ima geData['name'], $this->conf->get('/config/settings/allowedExtentio nsArr'))) {
    header("HTTP/1.1 403 Forbidden");
    echo "Error. Wrong extention";
    } else {
    $fullpath = ROOT_DIR . $this->path . $imageData['name'];
    $result = @move_uploaded_ file($imageData['tmp_name'], $fullpath);
    if ($result) {
    chmod($fullpath , 0777);
    $FSItem = ivFSItem::creat e($fullpath);
    $FSItem->generateThumb( );
    $filename = ROOT_DIR . $this->path . 'folderdata.xml ';
    if (is_file($filen ame)) {
    $file = file_get_conten ts($filename);
    $file = preg_replace('/\s*fileCount=\" \d*\"\s*/i', ' ', $file);
    $result = @file_put_conte nts($filename, $file);
    }
    echo "File {$imageData['name']} succesfully uploaded";
    } else {
    header("HTTP/1.1 500 Internal Server Error");
    echo "Error. File {$imageData['name']} wasn't uploaded";
    }
    }
    }[/PHP]
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    chmod the directory in which the images are stored.

    Comment

    • petershaman
      New Member
      • Nov 2008
      • 3

      #3
      Originally posted by Markus
      chmod the directory in which the images are stored.
      It's 777, I'm sure, that this code needs some modification, I've had similar issue with other upload script, in which I solved the problem, but this one seems to be harder.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by petershaman
        It's 777, I'm sure, that this code needs some modification, I've had similar issue with other upload script, in which I solved the problem, but this one seems to be harder.
        So is it when you try and view the image that you get the access forbidden error? After you upload the image, what is the permission on the image?

        Comment

        • petershaman
          New Member
          • Nov 2008
          • 3

          #5
          It's a bit more complicated, since it's a flash gallery, and upload is based on flash too.

          When trying to upload script detects, that file has 600 permissions, and stopping uploading, so nothing can be done, but in fact yes, when I'm using normal (only php based upload, ot thru ftp), permissions are the same - 600 not like it should be 644.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            Originally posted by petershaman
            [...] since I'm getting an error 403. [...]
            Looking over your code, wouldn't that be caused by line #15?

            If so, then why do you assume this is a permission error?
            Seems like your code is rejecting the file extension to me.

            Comment

            Working...