SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP auto updater help

    Hi, i found a php updater script
    Code PHP:
    <h1>DYNAMIC UPDATE SYSTEM</h1>
    <?
    ini_set('max_execution_time',60);
    //Check For An Update
    $getVersions = file_get_contents('cmstest/current-release-versions.php') or die ('ERROR');
    if ($getVersions != '')
    {
    	echo '<p>CURRENT VERSION: '.get_siteInfo('CMS-Version').'</p>';
    	echo '<p>Reading Current Releases List</p>';
    	$versionList = explode("\n", $getVersions);	
    	foreach ($versionList as $aV)
    	{
    		if ( $aV > get_siteInfo('CMS-Version')) {
    			echo '<p>New Update Found: v'.$aV.'</p>';
    			$found = true;
     
    			//Download The File If We Do Not Have It
    			if ( !is_file(  $_ENV['site']['files']['includes-dir'].'/UPDATES/MMD-CMS-'.$aV.'.zip' )) {
    				echo '<p>Downloading New Update</p>';
    				$newUpdate = file_get_contents('cmstest/MMD-CMS-'.$aV.'.zip');
    				if ( !is_dir( $_ENV['site']['files']['includes-dir'].'/UPDATES/' ) ) mkdir ( $_ENV['site']['files']['includes-dir'].'/UPDATES/' );
    				$dlHandler = fopen($_ENV['site']['files']['includes-dir'].'/UPDATES/MMD-CMS-'.$aV.'.zip', 'w');
    				if ( !fwrite($dlHandler, $newUpdate) ) { echo '<p>Could not save new update. Operation aborted.</p>'; exit(); }
    				fclose($dlHandler);
    				echo '<p>Update Downloaded And Saved</p>';
    			} else echo '<p>Update already downloaded.</p>';	
     
    			if ($_GET['doUpdate'] == true) {
    				//Open The File And Do Stuff
    				$zipHandle = zip_open($_ENV['site']['files']['includes-dir'].'/UPDATES/MMD-CMS-'.$aV.'.zip');
    				echo '<ul>';
    				while ($aF = zip_read($zipHandle) ) 
    				{
    					$thisFileName = zip_entry_name($aF);
    					$thisFileDir = dirname($thisFileName);
     
    					//Continue if its not a file
    					if ( substr($thisFileName,-1,1) == '/') continue;
     
     
    					//Make the directory if we need to...
    					if ( !is_dir ( $_ENV['site']['files']['server-root'].'/'.$thisFileDir ) )
    					{
    						 mkdir ( $_ENV['site']['files']['server-root'].'/'.$thisFileDir );
    						 echo '<li>Created Directory '.$thisFileDir.'</li>';
    					}
     
    					//Overwrite the file
    					if ( !is_dir($_ENV['site']['files']['server-root'].'/'.$thisFileName) ) {
    						echo '<li>'.$thisFileName.'...........';
    						$contents = zip_entry_read($aF, zip_entry_filesize($aF));
    						$contents = str_replace("\r\n", "\n", $contents);
    						$updateThis = '';
     
    						//If we need to run commands, then do it.
    						if ( $thisFileName == 'upgrade.php' )
    						{
    							$upgradeExec = fopen ('upgrade.php','w');
    							fwrite($upgradeExec, $contents);
    							fclose($upgradeExec);
    							include ('upgrade.php');
    							unlink('upgrade.php');
    							echo' EXECUTED</li>';
    						}
    						else
    						{
    							$updateThis = fopen($_ENV['site']['files']['server-root'].'/'.$thisFileName, 'w');
    							fwrite($updateThis, $contents);
    							fclose($updateThis);
    							unset($contents);
    							echo' UPDATED</li>';
    						}
    					}
    				}
    				echo '</ul>';
    				$updated = TRUE;
    			}
    			else echo '<p>Update ready. <a href="?doUpdate=true">&raquo; Install Now?</a></p>';
    			break;
    		}
    	}
     
    	if ($updated == true)
    	{
    		set_setting('site','CMS',$aV);
    		echo '<p class="success">&raquo; CMS Updated to v'.$aV.'</p>';
    	}
    	else if ($found != true) echo '<p>&raquo; No update is available.</p>';
     
     
    }
    else echo '<p>Could not find latest realeases.</p>';

    where it says
    Code PHP:
    echo '<p>CURRENT VERSION: '.get_siteInfo('CMS-Version').'</p>';
    how would i get the site info in another file to this one?

    BTW the reason the files arn't on a website is because im developing through files

  2. #2
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,177
    Mentioned
    63 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Lordtenteth View Post
    where it says
    Code PHP:
    echo '<p>CURRENT VERSION: '.get_siteInfo('CMS-Version').'</p>';
    how would i get the site info in another file to this one?
    Can you elaborate please

  3. #3
    SitePoint Member
    Join Date
    Dec 2012
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well I want to know how i can add "CMS-Version" on another file and bring it to this file. (im a beginner at PHP)


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •