Кемеровские программисты php общаются здесь
Anonymous
Не удалось заархивировать и загрузить файлы. Возврат символов в терминалах
Сообщение
Anonymous » 14 май 2024, 10:45
мой почтовый индекс для загрузки не работает. В архиве содержится несколько файлов xls.
При попытке создать файл экспорта возникла ошибка.
Я использую PHP.
Код такой:
Код: Выделить всё
$directory = Yii::getAlias('@console/runtime/tmp');
if (!file_exists($directory)) {
mkdir($directory);
}
$this->zip = new \ZipArchive();
$this->zipFile = tempnam($directory, "zip");
....
$html = 'noname';
$output = '';
$output .= "\n";
$output .= "\n";
$output .= "\n";
$output .= "\n";
$output .= "\n";
$output .= $html;
$output .= "\n";
$output .= "\n";
$fileName = "test" . '.xls';
if ($this->zip->open($this->zipFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) === TRUE) {
file_put_contents($fileName, $output);
$this->zip->addFile($fileName, basename($fileName));
}
$this->zip->close();
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename=' . $this->getFilename());
header("Content-Length: " . filesize($this->zipFile));
header("Pragma: no-cache");
header("Expires: 0");
readfile($this->zipFile);
exit();
Результат
Что мне сделать, чтобы все заработало? Я уже потратил 3 дня на эту проблему
Подробнее здесь:
https://stackoverflow.com/questions/784 ... -terminals
1715672747
Anonymous
мой почтовый индекс для загрузки не работает. В архиве содержится несколько файлов xls. При попытке создать файл экспорта возникла ошибка. Я использую PHP. Код такой: [code]$directory = Yii::getAlias('@console/runtime/tmp'); if (!file_exists($directory)) { mkdir($directory); } $this->zip = new \ZipArchive(); $this->zipFile = tempnam($directory, "zip"); .... $html = 'noname'; $output = ''; $output .= "\n"; $output .= "\n"; $output .= "\n"; $output .= "\n"; $output .= "\n"; $output .= $html; $output .= "\n"; $output .= "\n"; $fileName = "test" . '.xls'; if ($this->zip->open($this->zipFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) === TRUE) { file_put_contents($fileName, $output); $this->zip->addFile($fileName, basename($fileName)); } $this->zip->close(); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename=' . $this->getFilename()); header("Content-Length: " . filesize($this->zipFile)); header("Pragma: no-cache"); header("Expires: 0"); readfile($this->zipFile); exit(); [/code] Результат [img]https://i.sstatic.net/82PmsVUT.png[/img] Что мне сделать, чтобы все заработало? Я уже потратил 3 дня на эту проблему Подробнее здесь: [url]https://stackoverflow.com/questions/78476518/zipping-and-download-files-failed-returning-symbols-in-the-terminals[/url]