【发布时间】:2011-06-25 03:00:48
【问题描述】:
尝试在服务器上调用 mkdir() 时出现以下错误...
警告:mkdir() [function.mkdir]: 权限被拒绝 /home/server/public_html/wp-content/themes/mytheme/catimages/cat-images.php 在第 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;
}
【问题讨论】:
-
你可能需要设置 mkdir 的资源标志 ;)
-
:) 这实际上很有趣:你怎么知道? -> 您收到警告:... Permision denied ... ,因此您知道该文件夹不可被网络服务器用户写入。如果您有 ssh 访问权限,请执行 chmod -R 777 /home/server/public_html/wp-content,如果您没有 ssh 访问权限,您可以打开您最喜欢的 ftp 客户端,浏览到 wp-content 文件夹,然后右键单击在 wp-content 上,大多数 ftp 客户端都会在附近的某个地方有一个权限选项卡或框,您将使用它来更改权限。
-
@poelinca 如果可以的话,我会投反对票。您是否认真建议他的目录是世界可读的,所以“问题消失了”?!
-
@Linus Kleen:毫无疑问,他的 wp-content 文件已经成为世界可读的文件。它们不可移动,是的,从外观上看,他需要访问才能编写一些文件,您将如何去做?你测试文件夹是否可写,如果不是,你不再写文件了?这是一个解决方案吗?你说得对,应该是
chmod -R 777 /home/server/public_html/wp-content/uploads,或者是更好的chown -R "webserveruser" /home/server/public_html/wp-content/uploads -
@poelinca:这正是“组”权限的正确用例 - 您仍然拥有目录(和文件),但您允许访问来自另一个组的用户。 777可能是多余的;当您需要管理文件(删除旧文件等)时,将所有权授予服务器用户可能会给您带来麻烦。
标签: php error-handling mkdir