一旦用户提交表单,我就会运行此代码。这个想法是保存一个名为“message_timestamp”的新文件,其中timestamp是当前的日期和时间。它需要保存在misc文件夹中,该文件夹与此php文件位于同一目录中。
我的代码:
if (isset($_POST['submitIssue'])) {
$type = $_POST['typeOfIssue'];
$prefName = $_POST['preferredName'];
$email = $_POST['userEmail'];
$details = $_POST['detailedReport'];
date_default_timezone_set('Atlantic/Bermuda');
$date = new DateTime('now');
$date = $date->format('Y-m-d_H:i:s');
$date = trim($date);
$fileName = "misc/message_" . $date;
$out = "Issue Alert!\nType of issue: " . $type . "\n\nSubmitted by " . $prefName . "\nEmail ID: " . $email . "\nSubmitted at: " . $date . "\n\nDetails: " . $details;
$myFile = fopen($fileName,"w") or die("Cannot open file!");
fwrite($myFile, $out);
fclose($myFile);
}
我尝试删除空格并查找转义字符。但只要将$ date附加到文件名,我就会收到错误:
fopen(misc / message_2018-02-0210:47:41):无法打开流:无效 第76行的C:\ MAMP \ htdocs \ A2 \ report.php中的参数
如果我没有把时间戳放在上面,我可以让它工作。有什么建议吗?