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

标签 php error-handling 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 并且主题文件夹中的文件是可写的,但这并不一定意味着我想上传文件夹是可写的。

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

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)

关于php - mkdir() 上的权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4962047/

相关文章:

c - 将多个目录添加到 mkdir

php - 空白页且无法下载 PHPExcel

php - 在 php 中使用正则表达式将 url 转换为域

optimization - Adam 优化器错误 : one of the variables needed for gradient computation has been modified by an inplace operation

r - R中的“Too few positive probabilities”错误

php:在表单提交时创建目录?

bash - 在 .environment 文件中定义一个变量并在 .sh 文件中使用(引用)该变量

php - PDO 连接器无法在具有多个实例的页面上使用

php - 节点链接树和数据由 PHP 在 json 文件中填充

powershell - PowerShell Pscx Expand-Archive方法故障检测