Add files and directory to a specific subdirectory

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

 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 this file, my folder structure looks like this:

enter image description here

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

Result: wordpress/wp-content/themes/My_Theme (including all files and subdirectories inside)

How can i do this?

+7
php zip ziparchive
source share
2 answers

I answer my question and the answer is simple: just define the second parameter: $zip->addFile($file, 'wordpress/wp-content/themes/' . $theme_name . '/' . $file_name);

+4
source share

You can use http://php.net/manual/en/function.rename.php . This should do what you are looking for.

0
source share

All Articles