我想将文件和图像文件夹从插件文件夹移动到主题文件夹。我成功地将文件移动到另一个文件夹并成功创建图像文件夹,但是当我将图像移动到主题"图像"文件夹它不起作用,我不知道为什么它不起作用。
我还允许所有文件= 777
这是我的代码:
//========= Move files from Plugin to Current Theme
$foo_theme_directory = get_option('foo_theme_directory');
if($foo_theme_directory == 'on'){
$foo_theme_dir = get_template_directory()."/foo";
define('FOO_THEME_DIR', $foo_theme_dir);
if(file_exists(FOO_THEME_DIR)){
$foo_plugin_dir = plugin_dir_path( __FILE__ );
$foo_image_dir = get_template_directory()."/foo/images";
define('FOO_IMAGE_DIR', $foo_image_dir);
if(!file_exists(FOO_IMAGE_DIR)){
mkdir(FOO_THEME_DIR.'/images', 0777, true);
}
// Move Images to images folder
copy($foo_plugin_dir.'foo/images/foo_icon_arrow.png', $foo_images_dir.'/foo_icon_arrow.png');
copy($foo_plugin_dir.'foo/images/foo_article_icon_img.png',
$foo_images_dir.'/foo_article_icon_img.png');
copy($foo_plugin_dir.'foo/images/foo_bg_reply.png', $foo_images_dir.'/foo_bg_reply.png');
copy($foo_plugin_dir.'foo/images/foo_breadcrum_sep.png', $foo_images_dir.'/foo_breadcrum_sep.png');
copy($foo_plugin_dir.'foo/images/foo_large.png', $foo_images_dir.'/foo_large.png');
copy($foo_plugin_dir.'foo/images/foo_med.png', $foo_images_dir.'/foo_med.png');
copy($foo_plugin_dir.'foo/images/foo_search_btn.png', $foo_images_dir.'/foo_search_btn.png');
// Move files to foo folder
copy($foo_plugin_dir.'foo/foo_artilces_list.php', FOO_THEME_DIR.'/foo_artilces_list.php');
copy($foo_plugin_dir.'foo/foo_style.css', FOO_THEME_DIR.'/foo_style.css');
copy($foo_plugin_dir.'foo/single-foo_articles.php', FOO_THEME_DIR.'/single-
foo_articles.php');
}
else{
//echo "No";
}
}
我没有收到图片无法复制的错误。任何想法
答案 0 :(得分:0)
好的,我得到了解决方案
我正在使用此代码:
// Move Images from plugin folder to theme/foo/images folder
$foo_images = opendir($foo_plugin_img_dir);
while($foo_read_image = readdir($foo_images)){
if($foo_read_image != '.' && $foo_read_image != '..'){
if (!file_exists($foo_read_image)){
copy($foo_plugin_img_dir.$foo_read_image, FOO_IMAGE_THEME_DIR.'/'.$foo_read_image);
}
}
}
而不是这段代码:
// Move Images to images folder
copy($foo_plugin_dir.'foo/images/foo_icon_arrow.png', $foo_images_dir.'/foo_icon_arrow.png');
copy($foo_plugin_dir.'foo/images/foo_article_icon_img.png',
$foo_images_dir.'/foo_article_icon_img.png');
copy($foo_plugin_dir.'foo/images/foo_bg_reply.png', $foo_images_dir.'/foo_bg_reply.png');
copy($foo_plugin_dir.'foo/images/foo_breadcrum_sep.png', $foo_images_dir.'/foo_breadcrum_sep.png');
copy($foo_plugin_dir.'foo/images/foo_large.png', $foo_images_dir.'/foo_large.png');
copy($foo_plugin_dir.'foo/images/foo_med.png', $foo_images_dir.'/foo_med.png');
copy($foo_plugin_dir.'foo/images/foo_search_btn.png', $foo_images_dir.'/foo_search_btn.png');
此解决方案非常适合我