Professional Web Applications Themes

chown / chgrp of a http owned file after upload - PHP Development

Hiya, I have written as part of my CMS, an image upload system, now when the images are placed in the destination folder, they are owned by httpd.root and I need to get them to be owned by siteuser.sitegroup. I have tried to chmod and chgrp it to siteuser.sitegroup but it gives permission denied errors. Is there any way round this without enabling run as root? Or is there a safe way to do this? Thanks....

  1. #1

    Default chown / chgrp of a http owned file after upload

    Hiya,

    I have written as part of my CMS, an image upload system, now when the
    images are placed in the destination folder, they are owned by httpd.root
    and I need to get them to be owned by siteuser.sitegroup.

    I have tried to chmod and chgrp it to siteuser.sitegroup but it gives
    permission denied errors.

    Is there any way round this without enabling run as root? Or is there a safe
    way to do this?

    Thanks.


    Bix Guest

  2. #2

    Default Re: [PHP] chown / chgrp of a http owned file after upload

    you could setup a cronjob running as root which chowns the files.
    or maybe you can so something with sudo




    ------------------------
    --
    Adrian
    mailto:adrianplanetcoding.net
    www: [url]http://www.planetcoding.net[/url]
    www: [url]http://www.webskyline.de[/url]


    Adrian Guest

  3. #3

    Default Re: [PHP] chown / chgrp of a http owned file after upload

    Not sure about cron, but will look into sudo.

    Thanks!
    "Adrian" <adrianplanetcoding.net> wrote in message
    news:622461083.20030806132548planetcoding.net...
    > you could setup a cronjob running as root which chowns the files.
    > or maybe you can so something with sudo
    >
    >
    >
    >
    > ------------------------
    > --
    > Adrian
    > mailto:adrianplanetcoding.net
    > www: [url]http://www.planetcoding.net[/url]
    > www: [url]http://www.webskyline.de[/url]
    >
    >

    Bix Guest

  4. #4

    Default Re: [PHP] chown / chgrp of a http owned file after upload

    >I have written as part of my CMS, an image upload system, now when the
    >images are placed in the destination folder, they are owned by httpd.root
    >and I need to get them to be owned by siteuser.sitegroup.
    >
    >I have tried to chmod and chgrp it to siteuser.sitegroup but it gives
    >permission denied errors.
    >
    >Is there any way round this without enabling run as root? Or is there a
    >safe way to do this?
    You can ch(mod|own|grp) the files in the upload script, right after they
    are written to disk. chmod a+rwX is a good option if you are not overly
    concerned about the security of these files. Are you getting
    permission-denied errors when attempting to do this in your script, or
    afterwards, on the command-line?

    ---------------------------------------------------------------------
    michal migurski- contact info and pgp key:
    sf/ca [url]http://mike.teczno.com/contact.html[/url]

    Mike Migurski Guest

  5. #5

    Default Re: [PHP] chown / chgrp of a http owned file after upload

    This is the part of the code as it stands, it gives a permission denied
    error.

    $imtemp=$_FILES['file']['tmp_name'];
    $imsize=$_FILES['file']['size'];
    $imname=$_FILES['file']['name'];
    if ($imsize > "100000") {zerror("Image too large","Please go back and
    correct, image must be less than 100k"); unlink ($imtemp);}
    if (file_exists($_SERVER['DOENT_ROOT'] . "/zeus_images/" .
    $_POST['folder'] . "/" . $imname)){zerror("File already exists","The
    filename $imname is already used"); unlink ($imtemp);}
    if (move_uploaded_file($imtemp,$_SERVER['DOENT_ROOT'] . "/zeus_images/"
    .. $_POST['folder'] . "/" . $imname)){
    if (chown($_SERVER['DOENT_ROOT'] . "/zeus_images/" . $_POST['folder']
    .. "/" . $imname, $site_user) && chmod($_SERVER['DOENT_ROOT'] .
    "/zeus_images/" . $_POST['folder'] . "/" . $imname,0644) &&
    chgrp($_SERVER['DOENT_ROOT'] . "/zeus_images/" . $_POST['folder'] . "/" .
    $imname,$site_group)){
    message ("file uploaded","File Uploaded!","File successfully uploaded
    as $imname to folder " . $_POST['folder']);
    }
    else {
    unlink ($_SERVER['DOENT_ROOT'] . "/zeus_images/" . $_POST['folder'] .
    "/" . $imname);
    zerror("File CHMOD / CHOWN / CHGRP error");
    }
    }
    else {
    zerror ("File Upload Error");
    }

    "Mike Migurski" <mikesaturn5.com> wrote in message
    news:Pine.GSO.4.52.0308061021310.2596atari...
    > >I have written as part of my CMS, an image upload system, now when the
    > >images are placed in the destination folder, they are owned by httpd.root
    > >and I need to get them to be owned by siteuser.sitegroup.
    > >
    > >I have tried to chmod and chgrp it to siteuser.sitegroup but it gives
    > >permission denied errors.
    > >
    > >Is there any way round this without enabling run as root? Or is there a
    > >safe way to do this?
    >
    > You can ch(mod|own|grp) the files in the upload script, right after they
    > are written to disk. chmod a+rwX is a good option if you are not overly
    > concerned about the security of these files. Are you getting
    > permission-denied errors when attempting to do this in your script, or
    > afterwards, on the command-line?
    >
    > ---------------------------------------------------------------------
    > michal migurski- contact info and pgp key:
    > sf/ca [url]http://mike.teczno.com/contact.html[/url]
    >

    Bix Guest

Similar Threads

  1. HTTP File upload ...
    By Raj in forum ASP Components
    Replies: 0
    Last Post: October 19th, 01:56 PM
  2. Replies: 3
    Last Post: November 30th, 11:27 AM
  3. upload xml file to http with certificate?
    By Jonathan Wax in forum ASP.NET Security
    Replies: 0
    Last Post: May 29th, 06:38 AM
  4. File.chown removes setuid permission
    By Andrew Walrond in forum Ruby
    Replies: 0
    Last Post: August 30th, 06:51 AM
  5. HTTP File Upload Using SSL
    By MSNews in forum ASP
    Replies: 3
    Last Post: July 31st, 07:39 PM

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139