Member Avatar for leegeorg07

Hi, I am working on a WP theme with a friend and I'm trying to figure out how to update the files on a regular basis. I will have a server that will be on at certain times (when an update is available) and I want a php file that will update all files in the folder IF it is a younger version. I was thinking of using a text file with the version number. What PHP could I use for this?

you will probably using cron?
and I think you might be able to get the date (of the file) from the server
and then compare it with the local file.?

Member Avatar for leegeorg07

okay, would you mind going through how I would do this. If you wouldn't mind?

If you need to know how cron works: some info from a random site
To get the date:

<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>

src: php.net

I don't know with which file you want to compare so I can't say something about that..

If you don't get it just ask =)

Member Avatar for leegeorg07

oh, okay that seems simple enough actually. I'm not quite sure how I would access the files on my server, what could I use for this? I already have this code to search through a directory:

<?php

    $dir="dir"; // Directory where files are stored
    $i=1;
    if ($dir_list = opendir($dir))
        {
            while(($filename = readdir($dir_list)) !== false)
                {
                	echo '<p><a href="'. $filename.'">'.$filename.'</a></p>';
                	$i++;
                }
            closedir($dir_list);
        }

    ?>

But what could I add so that the directory is from the server?

Member Avatar for leegeorg07

oh okay, that seems easy enough :) thanks

Member Avatar for leegeorg07

okay, I now have the code to check for an update:

$version=file_get_contents('current_version.txt');
  $d=date("D");
  if($d === "Tue")
    {
      echo 'checking for updates..<br/>';
      $current_version=file_get_contents('http://www.leegeorg07.co.cc/test/current_version.txt');
      if($current_version > $version)
        echo 'There is a newer version of this script available, please update at<br/>';        
      elseif($current_version < $version)
        echo'You are running a beta script, are you sure? Restore the latest stable version at<br/>';
      else
        echo 'You are running the current version';
    }

but I cant seem to access the files to download on the remote server, how could it be done?

I dunno, havent thought about that
My version downloads a zip file of the new script using a force download script that the user then unzips over the top of their existing folders
combining the two scripts given already

$version=file_get_contents('current_version.txt');
$d=date("D"); 
if($d === "Tue")  {  echo 'checking for updates..<br/>'; }
$current_version=file_get_contents('http://www.leegeorg07.co.cc/test/current_version.txt');
if($current_version > $version) { echo 'There is a newer version of this script available, please update <br/>';        
$dir="dir"; // Directory where files are stored
$i=1;
if ($dir_list = opendir($dir))  {  while(($filename = readdir ($dir_list)) !== false)  { echo '<a href="'.$filename.'">'.$filename.'</a><br>';
$i++;  }
 closedir($dir_list);
}
}
elseif($current_version < $version) { echo 'You are running a beta script, are you sure? Restore the latest stable version at<br/>'; }
else  echo 'You are running the current version';
}

untested implementation
( does this work ? )

force download script (filesave.php)

<?php if(!$file) return false;
header("Content-disposition: attachment; filename=$file");
if(!$filetype){ header('Content-type: application/pdf;'); }
else { header("Content-type: $filetype;" ); }
readfile("$file");
?>

accessed by <a href='filesave.php?file=filename&filetype=this%2Fthat'>download filename</a>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.