我需要从表单中获取数据并且:
这是我到目前为止所创建的.csv,目前只是下载。
<?php
if(isset($_POST['submit'])){
//collect form data
$email = $_POST['inf_field_Email'];
//other form data
//server side validation
if($email=='') {
$error[] = 'Email is required';
}
//create csv
if(!isset($error)){
$Content = "Email\n";
//set the data of the CSV
$Content .= "$email\n";
# set the file name and create CSV file
$FileName = "FormData_".date("d-m-y-h:i:s").".csv";
//this is where I can only create and download, I know the header is the issue here.
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . $FileName . '"');
echo $Content;
exit();
}
}
?>
任何有关存储在服务器上的帮助都将非常感激。我在运行Apache的AWS S3上。
根据以下建议 根据下面的建议,我现在直接写入服务器上的文件,但是每次提交都会复制标题行。
<?php
//same form data and validation as above
if(!isset($error)){
$Content = "Email\n";
$Content .= "$email\n";
# set the file name and create CSV file
$fp = fopen("Registration.csv","a");
$savestring = $Content;
fwrite($fp,$savestring);
fclose($fp);
echo"<h1>Your Data has been saved</h1>";
exit();
}
答案 0 :(得分:1)
在我看来,您可以在不包括主机的情况下组合前两个步骤。
https
加密数据。