<?
$faddr="$ftxt.txt";
if (strlen($opinion) < 2 and $action=="put") { $action = "list"; }
switch ($action) {
case "put":
$opinion = substr($opinion,0,255);
if (file_exists($faddr)) {
$file=fopen($faddr,"a");
} else {
# f2s.com must chmod 777 for room (permission denied)
$file=fopen($faddr,"w");
}
fputs($file,"$opinion\n");
fclose($file);
break;
case "del":
$ar=file($faddr);
$file=fopen($faddr,"w");
for ($i=0;$i<count($ar);$i++) {
if ($i <> $delline) {
echo "$i,$dellin<br>";
fputs($file,"$ar[$i]");
} else {
echo "Delete line $delline : ok<br>";
}
}
fclose($file);
break;
}
# action=list is default for all option
if (file_exists($faddr)) {
$ar=file($faddr);
echo "<ol>";
for ($i=0;$i<count($ar);$i++) {
echo "<form action=puttxt.php><input type=hidden name=delline value=$i>";
echo "<input type=hidden name=ftxt value=$ftxt>";
echo "<li>$ar[$i]";
echo "<input type=submit name=action value=del></form>";
}
echo "</ol>";
} else {
echo "Not found any opinion";
}
?>
จำนวน : 44 บรรทัด