0

我想 ...

  • move_uploaded_files到某个文件夹(比如说http://localhost/myproject/protected)。(而且 PHP 应该能够rm, mv, cp, ... 里面的一切protected
  • 例如,为用户启用/禁用任何文件的访问/下载http://my.ip.add.ress/myproject/protected/foo.barhttp://localhost/myproject/protected/foo.bar也不例外!)

...使用chmodchown我想知道这是否可能?!


PS我有个主意:

// 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");
?>

但我认为它不够安全:-{|)

OMT(另一件事)我做了以下事情:

  • chown -R www-data:www-data /var/www
  • chmod -R 0700 /var/www/myproject/protected

PHP 可以访问这些文件,但用户也可以访问它们。


编辑1:输出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)
4

1 回答 1

1

不要更改任何chmod你只需要chownapache然后只有你的 php 代码能够修改它

// 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);
于 2013-10-25T20:36:24.720 回答