Skip to content

Instantly share code, notes, and snippets.

@govindak
Created December 21, 2019 09:30
Show Gist options
  • Save govindak/8f3f8bb68c3ac258ab806ba642e804e7 to your computer and use it in GitHub Desktop.
Save govindak/8f3f8bb68c3ac258ab806ba642e804e7 to your computer and use it in GitHub Desktop.
wordpress downloader
<?php
// Download utility
ini_set("memory_limit", "-1");
set_time_limit(0);
function shailan_get_file( $url, $target ){
echo "<h3>Downloading file..</h3><br />";
if( FALSE !== file_put_contents( $target . "/" . basename($url), file_get_contents( $url ) ) ){
return $target . "/" . basename($url);
}
}
function shailan_dir_URL() {
$dirURL = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
$dirURL .= ( ($_SERVER["SERVER_PORT"] == "80") ? $_SERVER["SERVER_NAME"] : $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"] );
$dirURL .= dirname( $_SERVER['PHP_SELF'] ) . "/";
return $dirURL;
}
$dir = dirname(__FILE__);
$current_url = shailan_dir_URL();
if(@filetype($dir . "/wp-config-sample.php")=="file" || @filetype($dir . "/wp-config.php")=="file"){
echo "It appears that Wordpress has already been already uploaded and/or installed.<br />\n";
echo "This utility is designed for clean installs only.<br />";
die();
}
if(is_writable($dir)===false){
echo "It does not appear that the current directory is writable.<br />\n";
echo "Please correct and re-run this script.<br />\n";
die();
}
$availfiles = array();
if($dh = opendir($dir)){
while(($file = readdir($dh)) !== false){
if(filetype($dir."/".$file)=="file" && substr($file, 0, 9)=="wordpress"){
if(substr($file, strlen($file)-3)==".gz" || substr($file, strlen($file)-4)==".zip"){
$availfiles[] = $file;
}
}
}
closedir($dh);
}
if(count($availfiles)==0){
$availfiles[] = shailan_get_file( 'http://wordpress.org/latest.tar.gz', dirname(__FILE__) );
}elseif(count($availfiles)>1){
echo "Multiple verions of Wordpress archives detected.<br />\n";
echo "Please delete all but the one you wish to install, or delete all of them and allow this script to<br />\n";
echo "download the latest version available from Wordpress.org.<br />\n";
die();
}
echo "<br /><h3>Extracting..</h3><br />";
system("tar -zxvf " . $availfiles[0] , $buff);
echo "<br /><h3>Moving..</h3><br />";
system("mv -f " . $dir . "/wordpress/* " . $dir . "", $buff2);
echo "<br /><h3>Removing unnecessary files..</h3><br />";
system("rm -rf wordpress", $buff3);
echo "<br /><h3>Done.</h3><br />";
echo "<br /><h3>Install WP : <a href=\"" . $current_url ."wp-admin/install.php\">Proceed..</a></h3><br />";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment