【发布时间】:2015-05-12 21:07:06
【问题描述】:
我正在尝试在 WordPress 多站点子站点目录中创建一个目录。
子站点目录位于/home/site/site.com/wp-content/uploads/sites/site_id/,其中site_id 是子站点的实际id#。
我希望在 site_id 目录下创建一个目录,然后从我的网络中的其他位置向该目录添加一个文件。
这是我目前所拥有的:
// Get current site id
global $current_blog;
$shop_id = $current_blog->blog_id;
// Create directory for current site if does not exist
if (!file_exists(WP_CONTENT_DIR . '/uploads/sites/' . $shop_id . '/new-directory/')) {
mkdir(WP_CONTENT_DIR . '/uploads/sites/' . $shop_id . '/new-directory/', 0777, true);
}
//Copy download.php to new directory
$download_file = 'https://example.com/wp-content/plugins/new-directory/download.php';
$copy_download = 'https://example.com/wp-content/uploads/sites/' . $shop_id . '/new-directory/download.php';
if (!file_exists('https://example.com/wp-content/uploads/sites/' . $shop_id . '/new-directory/download.php')) {
copy($download_file, $copy_download);
}
当我运行这个时,我得到一个失败的打开流:第 30 行没有这样的文件或目录。第 30 行是 copy($download_file, $copy_download); 行。
【问题讨论】:
-
尝试删除
https://example.com。我认为copy主要只适用于本地文件。参见手册php.net/manual/en/function.copy.php -
将错误报告添加到文件顶部,紧跟在您的打开 PHP 标记之后,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);,然后是其余代码,看看它是否会产生任何结果。 -
example.com 位有效。我用
WP_CONTENT_DIR替换了https://example.com/wp-content,生活很美好!谢谢! -
太好了,很高兴听到它,不客气。你想让我把它作为答案发布吗?你不必,这是你的选择。我还建议使用
WP_CONTENT_DIR代替它。 -
我很乐意接受它作为答案。我喜欢它是一个简单的修复!