Re: User when script uploads a file?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



sorry I should have done reply all

On Apr 7, 2015, at 1:03 PM, Ashley Sheridan wrote:

On Tue, 2015-04-07 at 12:54 -0700, Jeffry Killen wrote:
Hi again;

I have a CMS that I use locally for dev purposes.

It has a facility for creating a sub directory with the name pattern:
lab_#

Within each lab_# are directories like lab_#/css, lab_#/js, lab_#/ php,
So I want to upload a file into dev_labs/lab_8/php and the php dir
has permissions set to 0755 ( web server user is the owner because
a php script created the dir and sub dirs).

Uploading to the target dir fails with the error write permission
denied.

So when a file is uploaded via a php script  who is the user? (in
Apache on MacOSX, or any version of a unix system)

Thanks in advance for info
JK


If PHP is responsible for handling the file upload then uploads are
under the user that Apache (or your web server of choice) is running as.
Typically the uploads go to your /tmp directory and are then moved out
by your scripts, but there are directives in Apache to change this
behavior.

I see you have a PHP script create the lab_# directories, but what about
the sub-directories within that? If PHP isn't also creating those, it
could lead to some issues with permissions.

Do you have some sample code that can illustrate the issue, as that
would help highlight any issues that might not be related to
permissions.

When the sub dir lab_# is created it is created from a template that
specifies what sub dirs to create via php script. So the owner user
of the lab_# and all its sub dirs is the web server user, in the case
of Mac OSX is _www. So why wouldn't an uploading script be able
to write to it without doing chmod(dirname($file), 0777), which is
what I have done in my script to get it to work. Once the file is successfully place in final destination dir, I use chmod to change the dir permissions
back to 0755.

function getFile($_FILES, $_dest)
             {
              $_errCol = array();
              if(is_uploaded_file($_FILES['sendFile']['tmp_name']))
                {
                 if(strpos( $_dest, 'd-') == 0)
                   {
                    $_dest = str_replace('d-', '', $_dest);
$_target = dirname(getcwd()). $_dest.'/'.basename($_FILES['sendFile']['name']);
                    if(is_writeable(dirname($_target)))
                      {
move_uploaded_file($_FILES['sendFile'] ['tmp_name'], $_target );
                       if(is_file($_target))
                         {
                          return 0;
                         }
                       else
                         {
return self::$_className."->getFile error: File upload failure: File not copied to destination dir.";
                         }
                      }
                    else
                      {
                       if(chmod(dirname($_target), 0777))
                         {
move_uploaded_file($_FILES['sendFile'] ['tmp_name'], $_target );
                          if(is_file($_target))
                            {
                             if(chmod(dirname($_target), 0755))
                               {
                                return 0;
                               }
                             else
                               {
return self::$_className."->getFile error: File upload failure: chmod failure.";
                               }
                            }
                         }
                       else
                         {
return self::$_className."->getFile error: File upload failure: destination dir does not have write permissions.";
                         }
                      }
                   }
         // ....etc...
I am using this system to develop and am having to debug it as I go
along.

To overload this thread, I have another issue at hand:
I thought that ZipArchive is a built-in class. At least that is the implication of the manual. But when I do $_zipper = new ZipArchive (as in below), I get a fatal error: class ZipArchive not found. Fatal error: Class 'ZipArchive' not found in /path/dev_lab/lab_8/php/ archiver.php on line 14
class _ARCHIVER
     {
      private static $_class = '';
      private static $_zipper = '';

      public function __construct()
             {
              self::$_class = get_class($this);
              self::$_zipper = new ZipArchive; // << fatal error
             }
       // ...etc....
      }
Thanks for time and attention
JK

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux