0

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?

3
Contributors
8
Replies
9
Views
7 Years
Discussion Span
Last Post by almostbob
0

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.?

0

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 =)

0

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?

0

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?

0

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>

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.