php中的压缩zip文件不';不显示拉丁字符
我为我的英语道歉。我需要一点帮助。我想将.csv压缩到zip中。 代码完成了这项工作,但当我打开.csv文件时,拉丁字符(á、é、í、ó、ú、ñ等)无法正确显示。UTF-8编码仅在文件未压缩时有效。这是我的代码:php中的压缩zip文件不';不显示拉丁字符,php,csv,character-encoding,zip,Php,Csv,Character Encoding,Zip,我为我的英语道歉。我需要一点帮助。我想将.csv压缩到zip中。 代码完成了这项工作,但当我打开.csv文件时,拉丁字符(á、é、í、ó、ú、ñ等)无法正确显示。UTF-8编码仅在文件未压缩时有效。这是我的代码: $archivo = "REPORTE_PUNTOS.csv"; $filename = "REPORTE_PUNTOS"; $zip = new ZipArchive(); if ($zip->open($filena
$archivo = "REPORTE_PUNTOS.csv";
$filename = "REPORTE_PUNTOS";
$zip = new ZipArchive();
if ($zip->open($filename, ZIPARCHIVE::CREATE) === true) {
$zip->addFile($archivo);
$zip->close();
} else {
echo 'Error creando '.$filename;
}
if (file_exists($filename)) {
//Download zip file
header("Content-Encoding: UTF-8");
header('Content-type: "application/zip"');
header('Content-Disposition: attachment; filename="'.$filename.'.zip"');
readfile($filename);
//Se borra el archivo zip
unlink($filename);
}
谢谢。试着用块下载,标题应该是这样的。 干得好,继续干
<?php
$archivo = "REPORTE_PUNTOS.csv";
$filename = "REPORTE_PUNTOS.zip";
$zip = new ZipArchive();
if ($zip->open($filename, ZIPARCHIVE::CREATE) === true) {
$zip->addFile($archivo);
$zip->close();
} else {
echo 'Error creando '.$filename;
}
if (file_exists($filename)) {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public", false);
header("Content-Description: File Transfer");
header("Content-Type: application/x-zip-compressed");
header("Accept-Ranges: bytes");
header("Content-Disposition: attachment; filename=\"" . $filename . "\";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($filename));
$chunkSize = 1024 * 1024;
$handle = fopen($filename, 'rb');
while (!feof($handle))
{
$buffer = fread($handle, $chunkSize);
echo $buffer;
ob_flush();
flush();
}
fclose($handle);
unlink($filename);
}
ZIP文件是二进制数据,因此UTF-8
没有任何意义…感谢您的回复。我尝试了你的代码,但结果相同。文件被压缩了。打开.csv文件时,拉丁字符(á、é、ñ、ñ)显示不正确。请尝试替换标题(“内容类型:application/csv;charset=UTF-8”);或者这样做:2。右键单击文件(.csv)|选择“使用记事本打开”。3.选择文件|另存为。4.导航到要保存文件的文件夹。5.输入文件名,并在文件名末尾附加.csv。6.选择UTF-8编码。7.单击保存。8.在Excel中打开新创建的文件以查看数据。