diff options
author | Steven Danz <steven-danz@kc.rr.com> | 2005-06-27 04:17:48 +0200 |
---|---|---|
committer | Steven Danz <steven-danz@kc.rr.com> | 2005-06-27 04:17:48 +0200 |
commit | b158d625b53833ef391800a991ad93d965d9425e (patch) | |
tree | 56913261bea090738c5b862fc3f2da06a7d6ca68 /inc/io.php | |
parent | 7131b6688badc1c1e9685aba4b222f147bc1df83 (diff) | |
download | rpg-b158d625b53833ef391800a991ad93d965d9425e.tar.gz rpg-b158d625b53833ef391800a991ad93d965d9425e.tar.bz2 |
track_changes.patch
Second go at including changes to allow users to sign up on
mailing lists so they may receive emails each time the page
they are interested in is updated.
darcs-hash:20050627021748-3ed6d-5f6993f51ab649e3928a513b0fbe7c421d880325.gz
Diffstat (limited to 'inc/io.php')
-rw-r--r-- | inc/io.php | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/inc/io.php b/inc/io.php index 46d218561..922d2af02 100644 --- a/inc/io.php +++ b/inc/io.php @@ -80,6 +80,88 @@ function io_saveFile($file,$content){ } /** + * Appends $content to $file. + * + * Uses gzip if extension is .gz + * + * @author Steven Danz <steven-danz@kc.rr.com> + * @return bool true on success + */ +function io_appendFile($file,$content){ + io_makeFileDir($file); + io_lock($file); + if(substr($file,-3) == '.gz'){ + $fh = @gzopen($file,'ab9'); + if(!$fh){ + msg("Appending to $file failed",-1); + return false; + } + gzwrite($fh, $content); + gzclose($fh); + }else{ + $fh = @fopen($file,'ab'); + if(!$fh){ + msg("Appending to $file failed",-1); + return false; + } + fwrite($fh, $content); + fclose($fh); + } + io_unlock($file); + return true; +} + +/** + * Delete exact match for $content from $file. + * + * Uses gzip if extension is .gz + * + * @author Steven Danz <steven-danz@kc.rr.com> + * @return bool true on success + */ +function io_deleteFromFile($file,$remove){ + if (@file_exists($file)) { + io_lock($file); + $content = ''; + if(substr($file,-3) == '.gz'){ + $mlist = gzfile($file); + }else{ + $mlist = file($file); + } + foreach ($mlist as $entry) { + if ($entry != $remove) { + $content = $content . $entry; + } + } + + if (!empty($content)) { + if(substr($file,-3) == '.gz'){ + $fh = @gzopen($file,'wb9'); + if(!$fh){ + msg("Removing content from $file failed",-1); + return false; + } + gzwrite($fh, $content); + gzclose($fh); + }else{ + $fh = @fopen($file,'wb'); + if(!$fh){ + msg("Removing content from $file failed",-1); + return false; + } + fwrite($fh, $content); + fclose($fh); + } + } else { + @unlink($file); + } + + io_unlock($file); + } + return true; +} + +/** * Tries to lock a file * * Locking is only done for io_savefile and uses directories |