php接受get參數,判斷文件是否存在

<?php

echo $_GET['id'];
$fileName=$_GET['id'].'.txt';

if(file_exists($fileName))
        {
            //"當前目錄中,文件存在",追加
            $myfile = fopen($fileName, "a") or die("Unable to open file!");
            $txt = "\n【".date('Y-m-d H:i:s',time())."】---"."文件存在,追加";
            fwrite($myfile, $txt);
            //記得關閉流
            fclose($myfile);
        }
        else
        {
            //"當前目錄中,文件不存在",新寫入
            $myfile = fopen($fileName, "w") or die("Unable to open file!");
            $txt = "【".date('Y-m-d H:i:s',time())."】---"."文件不存在,新創建";
            fwrite($myfile, $txt);
            //記得關閉流
            fclose($myfile);
        }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章