Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

enter image description here

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?

like image 257
Reza Avatar asked Jan 27 '17 12:01

Reza


1 Answers

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

like image 60
Reza Avatar answered Sep 30 '22 04:09

Reza