简体   繁体   中英

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. 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.

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:

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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