如何在php中的addfile压缩时保留txt自述文件中的换行符?

时间:2014-08-05 07:18:44

标签: php zip line break

我有一个txt文件,显示版权信息和地址与我的图片一起压缩。我使用php来做到这一点。一切正常,但在下载zip后打开ReadMe.txt时,所有换行都消失了。如何保持换行?我使用的代码:

    $date = date("y-m-d");
$zip = new ZipArchive;
$download =  'pics-' . $date . '.zip';
$zip->open($download, ZipArchive::CREATE);
foreach (glob("photos/*.jpg") as $file) { /* Add appropriate path to read content of zip */
$new_filename = substr($file,strrpos($file,'/') + 1);
$zip->addFile($file,$new_filename);
    //$zip->addFile($file);
}
$zip->addFile('/info/readme.txt', 'ReadMe.txt');
$zip->close();
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename = $download");
header('Content-Length: ' . filesize($download));
header("Location: $download");

1 个答案:

答案 0 :(得分:0)

试试以下

foreach (glob("photos/*.jpg") as $file) { /* Add appropriate path to read content of zip */
$new_filename = substr($file,strrpos($file,'/') + 1);
$file=$new_filename."<br />"

$zip->addFile($file);
}