colorful rat Ratfactor.com > Dave's Repos

htmlwarden

A flat HTML file Wiki in PHP
git clone http://ratfactor.com/repos/htmlwarden/htmlwarden.git

htmlwarden/save.php

Download raw file: save.php

1 <?php 2 require 'core.php'; 3 4 require_login(); 5 6 $page_name = $_REQUEST['page']; 7 $page_body = $_REQUEST['body']; 8 9 $ts = time(); # unix timestamp 10 11 $fname = "${GLOBALS['page_dir']}/${page_name}.html"; 12 $archival_fname = "${GLOBALS['archive_dir']}/${ts}_${page_name}.html"; 13 14 // Archive previous version 15 if(file_exists($fname)){ 16 $ok = rename($fname, $archival_fname); 17 if(!$ok){ return_error(500, 18 'Sorry, there was an error archiving the page.'); } 19 } 20 21 // Save new version 22 $ok = file_put_contents($fname, $page_body); 23 if(!$ok){ return_error(500, 24 'Sorry, there was an error saving the page.'); } 25 26 // Redirect to view new version 27 header("Location: index.php?page=$page_name");