Last active
February 12, 2024 09:20
-
-
Save tschoffelen/8087707 to your computer and use it in GitHub Desktop.
A simple PHP script that automatically downloads and unzips the latest version of Wordpress in the current directory (./), so that I don't have to download it and upload it to my server through FTP manually.
This file contains 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 | |
echo '<pre>'; | |
echo '<span style="color:blue">DOWNLOADING...</span>'.PHP_EOL; | |
// Download file | |
file_put_contents('wp.zip', file_get_contents('https://wordpress.org/latest.zip')); | |
$zip = new ZipArchive(); | |
$res = $zip->open('wp.zip'); | |
if ($res === TRUE) { | |
// Extract ZIP file | |
$zip->extractTo('./'); | |
$zip->close(); | |
unlink('wp.zip'); | |
// Copy files from wordpress dir to current dir | |
$files = find_all_files("wordpress"); | |
$source = "wordpress/"; | |
foreach ($files as $file) { | |
$file = substr($file, strlen("wordpress/")); | |
if (in_array($file, array(".",".."))) continue; | |
if (!is_dir($source.$file)){ | |
echo '[FILE] '.$source.$file .' -> '.$file . PHP_EOL; | |
rename($source.$file, $file); | |
}else{ | |
echo '[DIR] '.$file . PHP_EOL; | |
@mkdir($file); | |
} | |
} | |
// Remove wordpress dir | |
foreach ($files as $file) { | |
if (in_array($file, array(".",".."))) continue; | |
if (is_dir($file)){ | |
echo '[REM] '.$file . PHP_EOL; | |
@rmdir($file); | |
} | |
} | |
@rmdir('./wordpress'); | |
// Check if copy was successful | |
if(file_exists('index.php')){ | |
// Redirect to WP installation page | |
echo '<meta http-equiv="refresh" content="1;url=index.php" />'; | |
}else{ | |
echo 'Oops, that didn\'t work...'; | |
} | |
} else { | |
echo 'Oops, that didn\'t work...'; | |
} | |
function find_all_files($dir) { | |
$root = scandir($dir); | |
foreach($root as $value) { | |
if($value === '.' || $value === '..') {continue;} | |
$result[]="$dir/$value"; | |
if(is_file("$dir/$value")) {continue;} | |
foreach(find_all_files("$dir/$value") as $value) | |
{ | |
$result[]=$value; | |
} | |
} | |
return $result; | |
} | |
?> |
thank you man... very good
Just what i needed, thanks
Was looking for something like this. Thank you! I only changed the download to use https.
Good job, maybe you can add some lines like unlink(FILE); at the end :)
I've added the self-unlink as well as a check for write permissions in my fork.
I updated your code, now it will delete the wordpress dir and also the install.php https://gist.github.com/paperbonsai/404d96554e636c7033072e4697c9408c
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is nice. It worked perfect . Thank you.