Return to Snippet

Revision: 59906
at October 9, 2012 02:38 by nathan_roberts


Initial Code
<pre><?php

// Download utility
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 style='position:absolute;background:magenta;padding:10px;top:0;width:200px;margin:10px;'>Install WP : <a href=\"" . $current_url ."wp-admin/install.php\">Proceed..</a></h3><br />";

Initial URL


Initial Description
This script downloads the latest version of WordPress to your site rather than having to use FTP.

Initial Title
WordPress Install Script

Initial Tags
wordpress

Initial Language
PHP