简体   繁体   English

PHP将zip保存到磁盘

[英]PHP save zip to disk

I want to zip files uploaded by a user to a certain Location. 我想将用户上传的文件压缩到某个位置。 While the upload part works, I have no Idea how to zip the file. 虽然上传部分有效,但我不知道如何压缩文件。 I am able to create a zip, but do not now how to actually save it to a disk. 我能够创建一个zip,但现在不知道如何将其实际保存到磁盘。

Simply pass the desired destination path to the zip when creating it: 创建时,只需将所需的目标路径传递给zip:

$path = 'path/to/file.zip';
$zip = new ZipArchive();
$zip->open($path, ZipArchive::CREATE);
// add contents...
$zip->close();

This is gonna surely help you out....These are 2 well explained examples hope it helps .. 这肯定会帮助你....这些是2个很好解释的例子希望它有帮助..

  1. http://www.9lessons.info/2012/06/creating-zip-file-with-php.html http://www.9lessons.info/2012/06/creating-zip-file-with-php.html

  2. http://davidwalsh.name/create-zip-php http://davidwalsh.name/create-zip-php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM