简体   繁体   English

PHP字符串自动下载zip

[英]PHP strings to automatically downloaded zip

I have a php file which reads data from an user submitted form and puts it into two different strings. 我有一个php文件,该文件从用户提交的表单中读取数据,并将其放入两个不同的字符串中。 I want to put these strings in separate txt files and put them into a zip archive which would be downloaded by the user when he submits the form. 我想将这些字符串放在单独的txt文件中,并将它们放入一个zip归档文件中,该文件将由用户在提交表单时下载。

How can I do that? 我怎样才能做到这一点? And is there a way to give each zip an unique name so there wouldn't be any possible conflicts? 有没有一种方法可以给每个邮政编码一个唯一的名称,这样就不会有任何可能的冲突?

Create two text files with fwrite and then use the create_zip function described here http://davidwalsh.name/create-zip-php like this: 使用fwrite创建两个文本文件,然后使用http://davidwalsh.name/create-zip-php中所述的create_zip函数,如下所示:

$files_to_zip = array(
'textFileA.txt',
'textFileB.txt'
);
$zip_name = uniqid().'.zip';
$result = create_zip($files_to_zip, $zip_name);

And then use a HTTP header to download the ZIP file created. 然后使用HTTP标头下载创建的ZIP文件。

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

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