CVS: phpweather-1.x phpweather.inc,1.12,1.13 config-dist.inc,1.2,1.3
Brought to you by:
iridium
From: Martin G. <gim...@us...> - 2002-09-03 12:23:24
|
Update of /cvsroot/phpweather/phpweather-1.x In directory usw-pr-cvs1:/tmp/cvs-serv19406 Modified Files: phpweather.inc config-dist.inc Log Message: One can now specify $db_dir to place the databases somewhere else than the current directory. The '/tmp' default should probably be adapted for other platforms... Index: phpweather.inc =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/phpweather.inc,v retrieving revision 1.12 retrieving revision 1.13 diff -u -3 -r1.12 -r1.13 --- phpweather.inc 26 Aug 2002 19:44:40 -0000 1.12 +++ phpweather.inc 3 Sep 2002 12:23:20 -0000 1.13 @@ -31,8 +31,8 @@ } elseif ($useDBM) { /* Open the DBM databases: */ - $dbmMetar = dbmopen ("metar", "c"); - $dbmTimestamp = dbmopen ("metarTimestamp", "c"); + $dbmMetar = dbmopen ("$db_dir/metar", "c"); + $dbmTimestamp = dbmopen ("$db_dir/metarTimestamp", "c"); if (!$dbmMetar || !$dbmTimestamp) { echo "<p>Unable to open DBM files!</p>"; $useDBM = 0; /* turn off so rest of program won't use */ @@ -40,8 +40,8 @@ } elseif ($useDBA) { /* Open the DBM databases: */ - $dbmMetar = dba_open ("metar", "c", $DBAmethod); - $dbmTimestamp = dba_open ("metarTimestamp", "c", $DBAmethod); + $dbmMetar = dba_open ("$db_dir/metar", "c", $DBAmethod); + $dbmTimestamp = dba_open ("$db_dir/metarTimestamp", "c", $DBAmethod); if (!$dbmMetar || !$dbmTimestamp) { echo "<p>Unable to open DBA files!</p>"; $useDBA = 0; /* turn off so rest of program won't use */ @@ -66,13 +66,28 @@ } elseif ($useXML) { /* Read the XML file: */ - $XMLFile = 'cache.xml'; + $XMLFile = "$db_dir/cache.xml"; - // Check for existence of the file: - if (!file_exists($XMLFile) || - !is_readable($XMLFile) || - !is_writable($XMLFile)){ - echo "<p>XML file does not exist or we couldn't open it for read/write!</p>"; + // Check state of XML file: + if (!file_exists($XMLFile)) { + /* We try and make the file: */ + if (is_writable($db_dir)) { + $fp = fopen($XMLFile, 'w'); + if ($fp) { + fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<metardata>\n</metardata>\n"); + fclose($fp); + echo "<p>The XML file was succesfully created.</p>\n"; + } else { + echo "<p>Something went wrong with the creation of the XML file!</p>\n"; + } + } else { + /* We couldn't write to the directory... */ + echo "<p>The XML file does not exist and could not be " . + "created because <code>$db_dir</code> isn't writable!</p>\n"; + $useXML = 0; // Turn off so we do not try to use later + } + } elseif (!is_readable($XMLFile) || !is_writable($XMLFile)){ + echo "<p>The XML file does exist but we cannot open it for read/write!</p>"; $useXML = 0; // Turn off so we do not try to use later } else { $XMLMetar = array (); Index: config-dist.inc =================================================================== RCS file: /cvsroot/phpweather/phpweather-1.x/config-dist.inc,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- config-dist.inc 26 Aug 2002 19:44:40 -0000 1.2 +++ config-dist.inc 3 Sep 2002 12:23:20 -0000 1.3 @@ -40,6 +40,12 @@ /* the DBA handler to use, if $useDBA is set to 1: */ $DBAmethod = 'db2'; // or ndbm, gdbm, db3 if db2 doesn't work. + +/* The directory used by PHP Weather to store file-based databases. + * The webserver has to have write permission to the directory for + * this to work. */ +$db_dir = '/tmp'; + /* If you're using a database that requires you to log on, then set * the following variables. Make sure to protect the 'config.php' file * so that other people cannot read your password! |