I am attempting to create a directory in a WordPress Multisite subsite directory.
The subsite directory is located at /home/site/site.com/wp-content/uploads/sites/site_id/
where site_id is the actual id# of the subsite.
I’m looking to create a directory under the site_id directory, and then add a file to that directory from elsewhere in my network.
Here is what I have so far:
// 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);
}
When I run this, I get a failed to open stream: No such file or directory on line 30. Line 30 is the copy($download_file, $copy_download);
line.
As per OP’s request to close the question.
Remove
https://example.com
.https://example.com/wp-content
actually, being a “joint venture”.copy
mostly only works on local files.Plus, as I did think it (but didn’t actually say it), to replace that with
WP_CONTENT_DIR
in its place.