Created
October 30, 2017 13:02
-
-
Save Mosharush/da7004c247f41e54a9b8bcd77bce38fe to your computer and use it in GitHub Desktop.
Get latest Wordpress archive to server and extract files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Function to remove folders and files | |
| function rrmdir($dir) { | |
| if (is_dir($dir)) { | |
| $files = scandir($dir); | |
| foreach ($files as $file) | |
| if ($file != "." && $file != "..") rrmdir("$dir/$file"); | |
| rmdir($dir); | |
| } | |
| else if (file_exists($dir)) unlink($dir); | |
| } | |
| // function used to copy full directory structure from source to target | |
| function full_copy( $source, $target ) { | |
| if ( is_dir( $source ) ) | |
| { | |
| mkdir( $target, 0777 ); | |
| $d = dir( $source ); | |
| while ( FALSE !== ( $entry = $d->read() ) ) | |
| { | |
| if ( $entry == '.' || $entry == '..' ) | |
| { | |
| continue; | |
| } | |
| $Entry = $source . '/' . $entry; | |
| if ( is_dir( $Entry ) ) | |
| { | |
| full_copy( $Entry, $target . '/' . $entry ); | |
| continue; | |
| } | |
| copy( $Entry, $target . '/' . $entry ); | |
| } | |
| $d->close(); | |
| }else | |
| { | |
| copy( $source, $target ); | |
| } | |
| } | |
| // ----------------------------------------------------------- | |
| header( 'Content-type: text/plain;charset=utf8' ); | |
| $wp_url = 'https://wordpress.org/latest.zip'; | |
| $wp_zip_file = basename( $wp_url ); | |
| $wp_dir = __DIR__ . '/'; | |
| // Download wp zip archive | |
| if( ! copy( $wp_url, $wp_zip_file ) ){ | |
| die( 'Error: Can\'t get wp install file' ); | |
| } | |
| // Unzip wp archive | |
| $zip = new ZipArchive; | |
| if ( $zip->open( $wp_zip_file ) === TRUE ) { | |
| $zip->extractTo( $wp_dir ); | |
| $zip->close(); | |
| echo 'WP archive extract to ' . $wp_dir . PHP_EOL; | |
| } else { | |
| die( 'Error: Can\'t extract wp archive file' ); | |
| } | |
| full_copy( $wp_dir . 'wordpress', $wp_dir ); | |
| rrmdir( $wp_dir . 'wordpress' ); | |
| unlink( $wp_zip_file ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment