2

I have several hosting accounts with a WordPress install in the Root directory and several addon domains with Wordpress installed in sub-directories. I am looking to compress only the Wordpress install in the root and think looking for wp-admin, wp-content, and wp-includes can help me reach my goal.

I got lazy and have been using a script I found in a tutorial to compress installs in sub-directories but would like to understand more on how to target a specific directory or file. Can anyone point me in the direction of a good tutorial for this?

The script below is highly circulated, works well to zip everything in a directory, and can exclude specific files with $exclude_files[] = realpath( 'file name' ); but not exactly what I need.

<?php 
/* Exclude Files */
$exclude_files = array();
$exclude_files[] = realpath( $zip_file );
$exclude_files[] = realpath( 'Move-My-Site-Zipper.php' );


// Get real path for our folder
$rootPath = realpath('');

// Initialize archive object
$zip = new ZipArchive();
$zip->open('file.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);

// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY
);

foreach ($files as $name => $file)
{
    $file_path = $file->getRealPath();
    // Skip directories (they would be added automatically)
    if (!$file->isDir() && !in_array( $file_path, $exclude_files ))
    {
        // Get real and relative path for current file
        $filePath = $file->getRealPath();
        $relativePath = substr($filePath, strlen($rootPath) + 1);

        // Add current file to archive
        $zip->addFile($filePath, $relativePath);
    }
}

// Zip archive will be created only after closing object
$zip->close();
?>
KenMc
  • 23
  • 1
  • 3

0 Answers0