下载数据库的CSV文件后,是否可以上传它,然后更新所有更改的行?
我用来下载的代码:
function download_csv(){
$query = query("SELECT * FROM shrubs ORDER BY id DESC");
if($query->num_rows > 0){
$delimiter = ",";
$filename = "document_" . ".csv";
//create a file pointer
$f = fopen('php://memory', 'w');
//set column headers
$fields = array('id','Pラベル', 'アンケミラベル管理番号', '商品名', 'name');
fputcsv($f, $fields, $delimiter);
while($row = $query->fetch_assoc()){
$lineData = array($row['id'], $row['Pラベル'], $row['アンケミラベル管理番号'], $row['商品名'], $row['name']);
fputcsv($f, $lineData, $delimiter);
}
//move back to beginning of file
fseek($f, 0);
//set headers to download file rather than displayed
header('Content-Encoding: UTF-8');
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '";');
//output all remaining data on a file pointer
fpassthru($f);
}
exit;
}
我打算做的是创建一个输入,可以在其中选择新编辑的CSV文件,然后提交它。然后将上传新文件,我的想法是运行一个foreach循环,检查所有行,如果不匹配,则使用新数据更新行。