php生成临时文件,使用PHP处理内存中的存档(无需在磁盘上创建临时文件)
小編典典
我遇到了同樣的問題,但最終找到了一個不太明顯的解決方案,決定在這里分享。
我遇到了很棒的zip.lib.php/ unzip.lib.php腳本,它們phpmyadmin都位于“庫”目錄中。
使用zip.lib.php對我來說是一種魅力:
require_once(LIBS_DIR . 'zip.lib.php');
...
//create the zip
$zip = new zipfile();
//add files to the zip, passing file contents, not actual files
$zip->addFile($file_content, $file_name);
...
//prepare the proper content type
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=my_archive.zip");
header("Content-Description: Files of an applicant");
//get the zip content and send it back to the browser
echo $zip->file();
此腳本允許下載zip,而無需將文件作為真實文件或將zip本身保存為文件。
遺憾的是,此功能不是更通用的PHP庫的一部分。
更新: 確保從zip.lib.php開頭刪除以下檢查,否則腳本將終止:
if (! defined('PHPMYADMIN')) {
exit;
}
2020-05-29
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的php生成临时文件,使用PHP处理内存中的存档(无需在磁盘上创建临时文件)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 错误记录_PHP中把错误日志保
- 下一篇: php 定时缓存,php如何定时删除缓存