微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – mkdir()上的权限被拒绝

尝试在服务器上调用mkdir()时出现以下错误

Warning: mkdir() [function.mkdir]:
Permission denied in
/home/server/public_html/wp-content/themes/mytheme/catimages/cat-images.PHP
on line 373

功能如下.它试图在网站的“wp-content / uploads文件夹”下创建一个文件夹.我已经验证PHP版本是5.2.15并且主题文件夹中的文件是可写的,但这并不一定意味着我认为uploads文件夹是可写的.

如何确定uploads文件夹是否可写?

protected function category_images_base_dir()
{
    // Where should the dir be? Get the base WP uploads dir
    $wp_upload_dir = wp_upload_dir();
    $base_dir = $wp_upload_dir[ 'basedir' ];
    // Append our subdir
    $dir = $base_dir . '/cat-images';
    // Does the dir exist? (If not,then make it)
    if ( ! file_exists( $dir ) ) {
        mkdir( $dir ); //THIS IS LINE 373
    }
    // Now return it
    return $dir;
}
is_writable()可能是您正在寻找的功能.

http://cz.php.net/manual/en/function.is-writable.php说:

Returns TRUE if the filename exists and is writable. The filename argument may be a directory name allowing you to check if a directory is writable.

此外,下一行直接与此相关:

Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often ‘nobody’).

换句话说,检查您的目录是否可以通过Web服务器的用户ID写入 – 这可能与您的用户ID不同!设置适当的权限 – 例如将文件夹的用户组设置为服务器用户用户组,并将读,写和执行授予组. (chgrp somegroup uploads; chmod g r uploads; chmod g w uploads; chmod g x uploads)

原文地址:https://www.jb51.cc/php/137128.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐