Permalink
Browse files

Added new directory for additional scripts not in the book

  • Loading branch information...
Tom Igoe
Tom Igoe committed Oct 4, 2011
1 parent 586f365 commit 2405ebe1a1020fc2dc8863b40c81e39393bd4186
Showing with 53 additions and 0 deletions.
  1. +3 −0 additions/README.txt
  2. +3 −0 additions/datalog.txt
  3. +47 −0 additions/getThatFile.php
View
@@ -0,0 +1,3 @@
These files are not in "Making Things Talk" anywhere, but were created in response to questions about the book, class exercises using the book, or were left over after editing the book. Enjoy.
-Tom
View
@@ -0,0 +1,3 @@
454,343,454
343,343,232
56,12,78
View
@@ -0,0 +1,47 @@
<?php
/* Simple file reader/writer
Context: PHP
Created 30 Sep 2011
by Tom Igoe and Gabriella Levine
This script takes a HTTP request and either reads from
or writes to a file on the server.
If the HTTP request contains a parameter called data,
then the value of that parameter is appended to
the end of the file on the server.
If there's no data parameter, then the file is
printed out to the client as is.
You must make a file called datalog.txt in the same directory
as this script beforehand in order for it to work.
*/
// put the name and path of the text file in a variable.
// this is the text file where we'll store the data:
$filename = 'datalog.txt';
//make sure the file is not empty:
if (file_exists($filename)) {
// get the contents of the file
// and put them in a variable called $fileContents:
$fileContents = file_get_contents($filename);
// if there is new data from the client, it'll
// be in a request parameter called "data".
if (isset($_REQUEST['data'])) {
// append what the client sent as 'data' to
// the variable holding the file contents:
$fileContents = $fileContents . "\n". $_REQUEST['data'];
// put the file contents back into the file
// you're overwriting the whole file when you do this:
file_put_contents($filename, $fileContents);
} else {
// there was no data sent in the request
// so show the old stuff:
echo $fileContents;
}
}
?>

0 comments on commit 2405ebe

Please sign in to comment.