我目前有一个像这样的variables.php文件:
<?php
$rep_name = "John Doe";
$rep_phone = "555-555-5555";
$rep_email = "johndoe@email.com";
$rep_subject = "Agent Contact: JDoe";
$rep_price = "39.95";
?>
我想创建一个带有生成此表单的HTML页面 - 看起来像这样:
<form name="generatevariables" action="generate_variables_file.php" method="post">
Rep Name:<input name="rep_name" placeholder="John Doe"><br />
Rep Phone:<input name="rep_phone" placeholder="555-555-5555"><br />
Rep Email:<input name="rep_email" placeholder="johndoe@email.com"><br />
Rep Subject:<input name="rep_subject" placeholder="Agent Contact: JDoe"><br />
Rep Price:<input name="rep_price" placeholder="39.95">
</form>
然后他们会输入他们的信息,然后点击一个显示Generate的按钮。这将创建variables.php文件并将其下载到他们的计算机上,以便他们通过FTP上传:
<?php
$rep_name = "John Doe";
$rep_phone = "555-555-5555";
$rep_email = "johndoe@email.com";
$rep_subject = "Agent Contact: JDoe";
$rep_price = "39.95";
?>
然后可以上传并在整个网站中调用变量,就像我目前在最顶层调用变量一样。
这有意义吗?我需要rep能够生成自己的variables.php文件,网站的其余部分依赖于variables.php文件,以获取所有特定内容。
感谢。
答案 0 :(得分:0)
您可以设置一个合适的标题来强制下载,然后只用纯文本回显代码:
<?php
//generate_variables_file.php
header('Content-disposition: attachment; filename=variables.php');
header('Content-type: text/plain');
echo '<?php';
echo '$rep_name = "' . $_POST['rep_name'] . '";';
echo '$rep_phone = "' . $_POST['rep_phone'] . '";';
echo '$rep_email = "' . $_POST['rep_email'] .'";';
echo '$rep_subject = "' . $_POST['rep_subject'] .'";';
echo '$rep_price = "' . $_POST['rep_price'] .'";'
echo '?>';