I want ...
move_uploaded_files
to some folder (lets say http://localhost/myproject/protected
). (and PHP should be able to rm
, mv
, cp
, ... everything inside protected
)http://my.ip.add.ress/myproject/protected/foo.bar
(and http://localhost/myproject/protected/foo.bar
is not exception !)... using chmod
and chown
. I wonder if this is possible ?!
P.S. I have an idea :
// firstly chown -R www-data:www-data /var/www
<?php
//file : localhost/myproject/foo.php
//use following when access for user is disabled
shell_exec("chmod -R 0777 protected");
// edit the folder ...
// edit the folder ...
// edit the folder ...
shell_exec("chmod -R 0000 protected");
?>
But I don't think it is secure enough :-{|)
O.M.T. (One More Thing) I did following :
chown -R www-data:www-data /var/www
chmod -R 0700 /var/www/myproject/protected
PHP can access the files, but user can also access them.
EDIT 1 : Output for ps aux | egrep '(apache|httpd)'
:
root 12748 0.0 0.2 39984 8256 ? Ss 01:54 0:00 /usr/sbin/apache2 -k start
www-data 12755 0.0 0.1 40208 6008 ? S 01:54 0:00 /usr/sbin/apache2 -k start
www-data 12756 0.0 0.1 40008 4324 ? S 01:54 0:00 /usr/sbin/apache2 -k start
www-data 12757 0.0 0.1 40008 4324 ? S 01:54 0:00 /usr/sbin/apache2 -k start
www-data 12758 0.0 0.1 40008 4324 ? S 01:54 0:00 /usr/sbin/apache2 -k start
www-data 12759 0.0 0.1 40008 4324 ? S 01:54 0:00 /usr/sbin/apache2 -k start
sylap 12896 0.0 0.0 5904 860 pts/1 S+ 02:25 0:00 egrep --color=auto (apache|httpd)
Do not change any chmod you just need to chown to apache then only your php codes is able to modify this
// File name and username to use
$file_name= "foo.php";
$path = "/home/sites/php.net/public_html/sandbox/" . $file_name ;
$user_name = "apache";
// Set the user
chown($path, $user_name);