-2
を移動すると:、フォームからサーバー上のストアをCSVを作成し、私は、フォームからデータを取得する必要があり、リモート・サーバに
- csvファイルを作成します(この部分が行われ、作業している)
- サーバーへのアップロード.CSV現在だけでダウンロードを作成し、ここで
私がこれまで持っているものであるftp_put使ってリモートサーバに
<?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();
}
}
?>
サーバーに保存するだけであれば、どなたでも助けてください。私はAWS S3でApacheを実行しています。
下記アドバイス以下のアドバイスでは、サーバー上のファイルに直接書き込みを行っていますが、各送信時にヘッダー行を複製しています。
<?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();
}
大きなアドバイス、効率化のためのすべてのIm。サーバー上でファイルを作成するにはどうすればよいですか? –
'file_put_contents'は関数の1つです。 http://php.net/manual/en/function.file-put-contents.php – VladimirAus
簡単なCSV作成のための 'str_getcsv'関数も見てください:http:// php。 net/manual/ja/function.str-getcsv.php – VladimirAus