Add files and directory to a specific sub directory

I am using the following script to move the files of my directory (in this case My_Theme ) to the zip archive wordpress.zip .

define('CLIENT_PATH', $_SERVER['DOCUMENT_ROOT'] . '/wp_theme/clients_templates/' . str_replace(' ', '_', $_POST['title']));
$zip = new ZipArchive;
$zip->open('wordpress.zip', ZipArchive::CREATE);
foreach (glob(CLIENT_PATH . "/*.*") as $file) {
    echo $file . '<br>';
   $zip->addFile($file);
}
$zip->close();

Now when I download and unzip that file, my folder structure looks like this:

在这里输入图像描述

What I want is to move the directory My_Theme to wordpress/wp-content/themes/

The result would be: wordpress/wp-content/themes/My_Theme (including all the files and sub directories within)

How can I do this?


我回答我自己的问题,答案很简单:只需定义第二个参数: $zip->addFile($file, 'wordpress/wp-content/themes/' . $theme_name . '/' . $file_name);


You could use http://php.net/manual/en/function.rename.php. That should do what you're looking for.

链接地址: http://www.djcxy.com/p/94860.html

上一篇: 将渐变文字与删除线/线组合

下一篇: 将文件和目录添加到特定的子目录