[test] 書きこみテスト 専用スレッド 1 [テスト]

このエントリーをはてなブックマークに追加
274nobodyさん
<?php
// ファイル一覧を表示
$dir = opendir("./");
while($file = readdir($dir)) {
if(is_file("./$file")) {
print "<option>$file</option>\n";
}
}
closedir($dir);
?>
</select>
<input type="submit" name="open" value="開く">
<textarea name="contents" cols="30" rows="6">
<?php
// ファイル内容を表示
$file = $_POST['file'];
if ($_POST['open'] && $file) {
$text = file_get_contents($file);
$text = htmlspecialchars($text);
print $text;
}
?>
</textarea>
275nobodyさん:2007/05/23(水) 22:28:41 ID:???
<input type="submit" name="save" value="保存">
<input type="hidden" name="editfile" value="<?php print $file ?>">
</form>
<?php
// ファイルを保存
$editfile = $_POST['editfile'];
if ($_POST['save'] && $editfile) {
$fp = @fopen($editfile, 'w');
if (!$fp) print "このファイルには書き込みできません。<br>\n";
else {
$contents = $_POST['contents'];
fwrite($fp, $contents);
fclose($fp);
print "書き込み完了しました。<br>\n";
}
}
?>