0

我想让文本框中输入的名称和日期作为 .txt 文件的保存名称,如果有意义的话,答案会保存到。目前我可以让它使用名称变量,但不能同时使用?

这是我的代码:

<?php
$answer1="";
$answer2="";
$answer3="";
$answer4="";
$answer5="";
$answer6="";
$answer7="";
$answer8="";
if(isset($_POST['submit'])){ //if button is clicked do this:
    $name = $_POST['myname'];
    $date = $_POST['date'];
    $answer1 = $_POST['q1answer'];
    $answer2 = $_POST['q2answer'];
    $answer3 = $_POST['q3answer'];
    $answer4 = $_POST['q4answer'];
    $answer5 = $_POST['q5answer'];
    $answer6 = $_POST['q6answer'];
    $answer7 = $_POST['q7answer'];
    $answer8 = $_POST['q8answer'];
    $answersText = "QUESTION 1\r\n\r\n". $answer1. "\r\n\r\nQUESTION 2\r\n\r\n". $answer2. "\r\n\r\nQUESTION 3\r\n\r\n". $answer3. "\r\n\r\nQUESTION 4\r\n\r\n". $answer4. "\r\n\r\nQUESTION 5\r\n\r\n". $answer5. "\r\n\r\nQUESTION 6\r\n\r\n". $answer6. "\r\n\r\nQUESTION 7\r\n\r\n". $answer7. "\r\n\r\nQUESTION 8\r\n\r\n". $answer8. "\r\n\r\n";
    $file = fopen($name ".txt","w");
fwrite($file, $answersText);
fclose($file);
4

2 回答 2

0

我想你的意思是这样的?

$file = fopen('Answers/'.$name."_".$date.".txt","w");

非常小心地根据来自网络的输入保存文件名,这是您无法信任的输入,因此请务必彻底验证和清理输入的数据。

于 2013-06-14T08:26:22.623 回答
0

改变

 $file = fopen($name ".txt","w"); 

 $file = fopen($name . $date . ".txt","w");
于 2013-06-14T08:23:41.710 回答