Posted By

nathan_roberts on 10/09/12


Tagged

wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nathan_roberts


WordPress Install Script


 / Published in: PHP
 

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

  1. <pre><?php
  2.  
  3. // Download utility
  4. function shailan_get_file( $url, $target ){
  5. echo "<h3>Downloading file..</h3><br />";
  6.  
  7. if( FALSE !== file_put_contents( $target . "/" . basename($url), file_get_contents( $url ) ) ){
  8. return $target . "/" . basename($url);
  9. }
  10. }
  11.  
  12. function shailan_dir_URL() {
  13. $dirURL = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https://' : 'http://';
  14. $dirURL .= ( ($_SERVER["SERVER_PORT"] == "80") ? $_SERVER["SERVER_NAME"] : $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"] );
  15. $dirURL .= dirname( $_SERVER['PHP_SELF'] ) . "/";
  16.  
  17. return $dirURL;
  18. }
  19.  
  20. $dir = dirname(__FILE__);
  21. $current_url = shailan_dir_URL();
  22.  
  23. if(@filetype($dir . "/wp-config-sample.php")=="file" || @filetype($dir . "/wp-config.php")=="file"){
  24. echo "It appears that Wordpress has already been already uploaded and/or installed.<br />\n";
  25. echo "This utility is designed for clean installs only.<br />";
  26. die();
  27. }
  28.  
  29. if(is_writable($dir)===false){
  30. echo "It does not appear that the current directory is writable.<br />\n";
  31. echo "Please correct and re-run this script.<br />\n";
  32. die();
  33. }
  34.  
  35. $availfiles = array();
  36.  
  37. if($dh = opendir($dir)){
  38. while(($file = readdir($dh)) !== false){
  39. if(filetype($dir."/".$file)=="file" && substr($file, 0, 9)=="wordpress"){
  40. if(substr($file, strlen($file)-3)==".gz" || substr($file, strlen($file)-4)==".zip"){
  41. $availfiles[] = $file;
  42. }
  43. }
  44. }
  45. closedir($dh);
  46. }
  47.  
  48. if(count($availfiles)==0){
  49. $availfiles[] = shailan_get_file( 'http://wordpress.org/latest.tar.gz', dirname(__FILE__) );
  50. }elseif(count($availfiles)>1){
  51. echo "Multiple verions of Wordpress archives detected.<br />\n";
  52. echo "Please delete all but the one you wish to install, or delete all of them and allow this script to<br />\n";
  53. echo "download the latest version available from Wordpress.org.<br />\n";
  54. die();
  55. }
  56.  
  57. echo "<br /><h3>Extracting..</h3><br />";
  58. system("tar -zxvf " . $availfiles[0] , $buff);
  59.  
  60. echo "<br /><h3>Moving..</h3><br />";
  61. system("mv -f " . $dir . "/wordpress/* " . $dir . "", $buff2);
  62.  
  63. echo "<br /><h3>Removing unnecessary files..</h3><br />";
  64. system("rm -rf wordpress", $buff3);
  65.  
  66. echo "<br /><h3>Done.</h3><br />";
  67.  
  68. 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 />";

Report this snippet  

You need to login to post a comment.