guestbook can't open file (php)

20 views
Skip to first unread message

Bảo Nguyên

unread,
Apr 19, 2015, 1:37:24 PM4/19/15
to google-a...@googlegroups.com
run guestbook localhost good.
but upload app engine error can't open file.
code:
<html>
<head><title>My Guestbook</title></head>
<body>
<h1>Welcome to My Guestbook</h1>
<h2>Please write me a little note below</h2>
<form action="" method="POST">
<input type="text" name="user" placeholder="Name" />
<br />
<textarea cols="40" rows="5" name="note" placeholder="Comments" wrap="virtual"></textarea>
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php

if (isset($_POST['submit'])){

$user = $_POST['user'];
$note = $_POST['note'];

if(!empty($user) && !empty($note)) {
$msg = $user . ' : ' . $note;
//will open a file
$fp = fopen("notes.txt","a") or die("Can't open file");
//will write to a file
fwrite($fp, $msg."\n");
fclose($fp);
}
}
?>
 
<h2>The entries so far:</h2>
<?php
$file = fopen("notes.txt", "r") or exit("Unable to open file!");
//Output a line of the file until the end is reached
while(!feof($file))
  {
  //will return each line with a break
  echo fgets($file). '<br />';
  }
fclose($file);
?> 
</body>
</html>
app.yaml
guestbook.php
notes.txt

Bảo Nguyên

unread,
Apr 19, 2015, 1:38:31 PM4/19/15
to google-a...@googlegroups.com
abcd-1990.appspot.com

Vào 00:37:24 UTC+7 Thứ Hai, ngày 20 tháng 4 năm 2015, Bảo Nguyên đã viết:

Adam

unread,
Apr 19, 2015, 6:50:05 PM4/19/15
to google-a...@googlegroups.com
You can't write the the local filesystem in App Engine. You need to use Cloud Storage. See:

Reading and Writing Files
Reply all
Reply to author
Forward
0 new messages