Php上传表单userinput = filename

时间:2011-03-25 20:37:47

标签: php

好的构建php webform需要其中一个条目是文件名。

我怎样才能做到这一点?

这是我的PHP代码......

$filename = "output.txt"; #Must CHMOD to 666
$text = $_POST['bin'];
$text2 = $_POST['pcn'];
$text3 = $_POST['gnum'];
$text4 = $_POST['memid'];
$text5 = $_POST['urlen'];
$text6 = $_POST['urles'];
$text7 = $_POST['tlogo'];

 # Form must use POST. if it uses GET, use the line below:
#$text = $_GET['theformfieldname']; #POST is the preferred method

$fp = fopen ($filename, "w"); # w = write to the file only, create file if it does not exist, discard existing contents
if ($fp) {
fwrite ($fp, "$text\r\n");
fwrite ($fp, "$text2\r\n");
fwrite ($fp, "$text3\r\n");
fwrite ($fp, "$text4\r\n");
fwrite ($fp, "$text5\r\n");
fwrite ($fp, "$text6\r\n");
fwrite ($fp, "$text7\r\n");
fclose ($fp);

header("Location: logo.html"); 
}
else {
echo ("There was an error please submit your request again");
}

?>

确定需要$ filename =“output.txt”; 来自输入$ text3 = $ _POST ['gnum'];

类似于:

$ filename = $ _POST ['gnum']。txt; 但这不会工作..

提前致谢, 乔

3 个答案:

答案 0 :(得分:0)

而不是

$filename = $_POST['gnum'].txt;

你应该使用

$filename = $_POST['gnum'].".txt"; 

答案 1 :(得分:0)

我不是超级清楚你要问的是什么,但我想你想知道如何将'.txt'附加到$ _GET变量的末尾?

如果是这种情况,您只需要这样做:

$text3 = $_POST['gnum'] . '.txt';

答案 2 :(得分:0)

使用它来获取文件名。

$_FILES["file"]["name"]