开发者

Php upload form userinput = filename

Ok building a php webform need one of the entries to be the filename written.

How can I achieve this?

Here's my php code...

$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 ("The开发者_运维技巧re was an error please submit your request again");
}

?>

ok need $filename = "output.txt"; to be from the input $text3 = $_POST['gnum'];

something along the lines of:

$filename = $_POST['gnum'].txt; but this wont work..

Thanks in advance, Joe


instead of

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

you should use

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


I'm not super clear on what you're asking, but I think you want to know how to appent '.txt' to the end of the $_GET variable?

If that's the case, you just need to do this:

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


Use this for getting the file name.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜