php mkdir() 和 apache 所有权问题

发布于 2024-12-25 06:10:14 字数 329 浏览 2 评论 0原文

问题

我正在尝试通过 PHP 将文件上传到我自己的服务器。如果文件夹不存在,我首先尝试创建文件夹;

mkdir($folder, 0700);

我的脚本正在创建文件夹,但 apache 是该文件夹(和文件)的所有者,因此我无法访问我上传的文件。

我的服务器中关闭了安全模式。我仍然找不到解决这个问题的方法。

如果有人能帮助我解决这个问题,我会很高兴。

注意: 我试过0755,0777没有改变任何东西。 Apache 是所创建文件夹的所有者。

PROBLEM

I'm trying to upload files to my own server via PHP. If folder doesn't exist, first I attempt to create the folders;

mkdir($folder, 0700);

My script is creating the folders but apache is the owner of the folder (and file) so I can't access the file which I uploaded.

I have safe_mode off in my server. I still couldn't find a way around for this one.

I would be glad if anyone could help me out with this one.

NOTE:
I tried 0755, 0777 doesn't change anything. Apache is owner of the folder created.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

茶花眉 2025-01-01 06:10:14

我建议重新配置网络服务器以使用 suEXECsuPHP。这种方法的缺点是您被迫以 CGI 模式使用 PHP,而不是作为 Apache mod。不过,我还没有看到这在中低流量网站上成为问题。主要好处是您的脚本将以拥有它们的人的身份运行,因此您的脚本创建的任何新目录或文件将自动归该用户所有。

最终,如果您的问题只是与创建新目录而不是文件有关,并且您没有存储任何不应被窥视的内容,那么< code>chmod($path, 0755); 可以解决您的问题。

I'd suggest reconfiguring the web server to use suEXEC or suPHP. The drawback of this approach is that you're forced to use PHP in CGI mode rather than as an Apache mod. I haven't seen this become a problem on low- to mid-traffic sites, though. The main benefit is that your scripts will run as whoever owns them, and as such any new directories or files your script makes will automatically be owned by said user.

Ultimately, if your problem is just with the creation of new directories and not files, and you're not storing anything that shouldn't be read by prying eyes, then chmod($path, 0755); would fix your issue.

吝吻 2025-01-01 06:10:14

以下代码片段创建具有权限 777(或任何指定权限)的目录:

 $oldumask = umask(0);
 mkdir($path, 0777);
 umask($oldumask);

The following code snippet creates directories with permissions 777(or any specified permissions):

 $oldumask = umask(0);
 mkdir($path, 0777);
 umask($oldumask);
千笙结 2025-01-01 06:10:14

为什么首先将权限设置为 700? 755 将允许“任何人”读取您的文件和文件夹,并且在大多数情况下实际上是可以接受的。

Why do you set permissions to 700 in the first place? 755 will allow "anyone" to read your files and folders, and in most cases it's actually acceptable.

番薯 2025-01-01 06:10:14

当然。上传目录必须是other可写/可访问,即:xx7:

// fill APPPATH with a suitable directoy name

if ( ! file_exists(APPPATH . 'uploads'))
{
    mkdir(APPPATH . 'uploads', 0757, TRUE);
}

7: owner permissions, ie: rwx
5: group permissions, ie: rx
7: other permissions, ie: rwx

Of course. The upload dir must be other writable/accessible, ie: xx7:

// fill APPPATH with a suitable directoy name

if ( ! file_exists(APPPATH . 'uploads'))
{
    mkdir(APPPATH . 'uploads', 0757, TRUE);
}

7: owner permissions, ie: rwx
5: group permissions, ie: rx
7: other permissions, ie: rwx
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文