I'm creating and downloading a zip file using /usr/bin/zip
in PHP. The problem is that the zip file contains the csv files with the non-ASCII file names. I got the zero-byte file downloaded and the file is not valid.
chdir($tmp_dir); // this is the directory where the files are written into
// CSV files that will be included in the zip file.
// assuming that the file already exist in $tmp_dir
$files = array();
$filename = "ショップ" . date("Ymd") . ".csv";
$fpath = $tmp_dir. DS . mb_convert_encoding($filename, "SJIS", "UTF-8");
$files[] = $fpath;
// The zip file to be created
$zip_file = "archive_" . date("Ymd").".zip";
$cmd = "/usr/bin/zip $zip_path *.csv";
exec($cmd);
// Force download
$fpath = $zip_file;
header("Content-Type: application/zip");
header('Content-Disposition: attachment; filename="' . $zip_path . '"');
header('Accept-Ranges: bytes');
if ($this->isIE()) {
header("Cache-Control:private");
header("Pragma:private");
}
header('Content-Length: ' . filesize($fpath));
readfile($fpath);
I tried ZipArchive, but same problem occurs.
chdir($tmp_dir); // this is the directory where the files are written into
// CSV files that will be included in the zip file.
// assuming that the file already exist in $tmp_dir
$files = array();
$filename = "ショップ" . date("Ymd") . ".csv";
$fpath = $tmp_dir. DS . mb_convert_encoding($filename, "SJIS", "UTF-8");
$files[] = $fpath;
// The zip file to be created
$zip_file = "archive_" . date("Ymd").".zip";
$zip = new ZipArchive();
$zip->open($zip_path, ZipArchive::CREATE);
foreach ($files as $v) {
$zip->addFile(basename($v));
}
$zip->close();
// Force download
$fpath = $zip_file;
header("Content-Type: application/zip");
header('Content-Disposition: attachment; filename="' . $zip_path . '"');
header('Accept-Ranges: bytes');
if ($this->isIE()) {
header("Cache-Control:private");
header("Pragma:private");
}
header('Content-Length: ' . filesize($fpath));
readfile($fpath);
Is there any workaround for this? When I removed the Japanese characters from the file name, it is ok.