7

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?

Community
  • 1
  • 1
Reza
  • 513
  • 3
  • 7
  • 20
  • You mean with code, right? – Asier Paz Feb 03 '17 at 12:50
  • Also. You are unzipping the zip manually so, does the move process need to be done zipped or unzipped? – Asier Paz Feb 03 '17 at 12:51
  • @AsierPaz I don't need to unzip the file on the web server. The user can unzip it when he has downloaded it on his computer. And yes, the directory should be added to the specific directory of the zip archive with code, not manually. – Reza Feb 03 '17 at 13:00

2 Answers2

4

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);

Reza
  • 513
  • 3
  • 7
  • 20
0

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

frobinsonj
  • 1,109
  • 9
  • 21
  • Why `rename()`? This will only rename the directory. Not really what I want. – Reza Feb 03 '17 at 13:05
  • @Reza rename("home/pomcanys/public_html/wp_theme/clients_templates/My_Theme","wordpress/wp-content/themes/My_Theme"); – frobinsonj Feb 03 '17 at 13:11
  • I have tried using it. The result is not looking much better as you may see here: http://i.imgur.com/Di8phY7.png – Reza Feb 03 '17 at 13:45