0
因此,我一直在試圖創建一個簡單的csv文件作爲下面的代碼,但沒有正確創建csv文件。它包含了我的.php文件中的html文本。csv文件創建不正確
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CVS File</title>
</head>
<body>
<table width="370" border="0" cellspacing="0" cellpadding="0">
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<tr>
<td><h1> Ultracom </h1></td>
<td align="right" valign="middle">
<input name="csv" type="file" id="csv" />
<input type="submit" id="btnsubmit" name="btnsubmit" value="Submit" />
</td>
</tr>
<tr>
<td><input type="submit" id="btnedit" name="btnedit" value="Edit" /></td>
<td></td>
</tr>
<tr>
<td><input type="submit" id="btnupdate" name="btnupdate" value="Update" /></td>
<td><input type="submit" id="btncancel" name="btncancel" value="Cancel" /></td>
</tr>
</form>
</table>
<?php
if (isset($_POST['btnupdate'])) {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=edited.csv');
$file = fopen("edited.csv","w");
$row = 2;
$a = "a";
$b = "b";
for ($r=0; $r < $row; $r++) {
$rows[$r] = $a.",".$b;
}
foreach ($rows as $details) {
fputcsv($file,explode(',',$details));
}
fclose($file);
}
?>
我的代碼有什麼問題嗎?我的代碼看起來與其他代碼大致相同,以創建我迄今在google上發現的csv文件。
**正確創建**可能意味着很多東西 – 2014-03-03 20:42:15
當我打開CSV文件,它包含: <!DOCTYPE HTML PUBLIC「 - // W3C // DTD XHTML 1.0 Transitional // EN「」http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd「>