$time = date("Y-m-d H:i:s"); $message = $message . "rn$this->sql" . "rn客户IP:$ip" . "rn时间 :$time" . "rnrn"; $server_date = date("Y-m-d"); $filename = $server_date . ".txt"; $file_path = "error/" . $filename; $error_content = $message; //$error_content="错误的数据库,不可以链接"; $file = "error"; //设置文件保存目录 //建立文件夹 if (!file_exists($file)) { if (!mkdir($file, 0777)) { //默认的 mode 是 0777,意味着最大可能的访问权 die("upload files directory does not exist and creation failed"); } } //建立txt日期文件 if (!file_exists($file_path)) { //echo "建立日期文件"; fopen($file_path, "w+"); //首先要确定文件存在并且可写 if (is_writable($file_path)) { //使用添加模式打开$filename,文件指针将会在文件的开头 if (!$handle = fopen($file_path, 'a')) { echo "不能打开文件 $filename"; exit; } //将$somecontent写入到我们打开的文件中。 if (!fwrite($handle, $error_content)) { echo "不能写入到文件 $filename"; exit; } //echo "文件 $filename 写入成功"; echo "——错误记录被保存!"; //关闭文件 fclose($handle); } else { echo "文件 $filename 不可写"; } } else { //首先要确定文件存在并且可写 if (is_writable($file_path)) { //使用添加模式打开$filename,文件指针将会在文件的开头 if (!$handle = fopen($file_path, 'a')) { echo "不能打开文件 $filename"; exit; } //将$somecontent写入到我们打开的文件中。 if (!fwrite($handle, $error_content)) { echo "不能写入到文件 $filename"; exit; } //echo "文件 $filename 写入成功"; echo "——错误记录被保存!"; //关闭文件 fclose($handle); } else { echo "文件 $filename 不可写"; } } } |