Skip to content

Instantly share code, notes, and snippets.

@toodooleedoo
Created February 1, 2015 23:15
Show Gist options
  • Save toodooleedoo/e40428bd4a9f7128deb4 to your computer and use it in GitHub Desktop.
Save toodooleedoo/e40428bd4a9f7128deb4 to your computer and use it in GitHub Desktop.
PHP File writer. Just drop in file then call eg writer.php?file=myfile&data=stuff in file
<?php
$data=$_REQUEST['data'];
$file='files/'.$_REQUEST['file'];
$fh = fopen($file, 'a+') or die("can't open file");
if (flock($fh, LOCK_EX)) {
if(!empty($file)) {
echo '**** Writing to file: '.$file.' ';
echo "\n";
if(empty($data)) { $data=""; }
echo $data;
echo "\n";
fwrite($fh, $data);
} else {
echo 'Improper parameters passed';
}
echo "\n";
fwrite($fh, "\n");
flock($fh, LOCK_UN);
}
fclose($fh);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment