ziparchive php example

Solutions on MaxInterview for ziparchive php example by the best coders in the world

showing results for - "ziparchive php example"
Jonah
22 Jan 2021
1<?php
2    $error = "";        //error holder
3    if(isset($_POST['createpdf'])){
4        $post = $_POST;     
5        $file_folder = "files/";    // folder to load files
6        if(extension_loaded('zip')){    // Checking ZIP extension is available
7            if(isset($post['files']) and count($post['files']) > 0){    // Checking files are selected
8                $zip = new ZipArchive();            // Load zip library 
9                $zip_name = time().".zip";          // Zip name
10                if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){       // Opening zip file to load files
11                    $error .=  "* Sorry ZIP creation failed at this time<br/>";
12                }
13                foreach($post['files'] as $file){               
14                    $zip->addFile($file_folder.$file);          // Adding files into zip
15                }
16                $zip->close();
17                if(file_exists($zip_name)){
18                    // push to download the zip
19                    header('Content-type: application/zip');
20                    header('Content-Disposition: attachment; filename="'.$zip_name.'"');
21                    readfile($zip_name);
22                    // remove zip file is exists in temp path
23                    unlink($zip_name);
24                }
25
26            }else
27                $error .= "* Please select file to zip <br/>";
28        }else
29            $error .= "* You dont have ZIP extension<br/>";
30    }
31?>
32<!DOCTYPE html>
33<html lang="en">
34<head>
35<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
36<title>Download As Zip</title>
37</head>
38<body>
39<center><h1>Create Zip</h1></center>
40<form name="zips" method="post">
41<?php if(!empty($error)) { ?>
42<p style=" border:#C10000 1px solid; background-color:#FFA8A8; color:#B00000;padding:8px; width:588px; margin:0 auto 10px;"><?php echo $error; ?></p>
43<?php } ?>
44<table width="600" border="1" align="center" cellpadding="10" cellspacing="0" style="border-collapse:collapse; border:#ccc 1px solid;">
45  <tr>
46    <td width="33" align="center">*</td>
47    <td width="117" align="center">File Type</td>
48    <td width="382">File Name</td>
49  </tr>
50  <tr>
51    <td align="center"><input type="checkbox" name="files[]" value="a.jpg" /></td>
52    <td align="center"><img src="files/image.png" title="Image" width="16" height="16" /></td>
53    <td>a.jpg</td>
54  </tr>
55  <tr>
56    <td align="center"><input type="checkbox" name="files[]" value="b.jpg" /></td>
57    <td align="center"><img src="files/image.png" title="Image" width="16" height="16" /></td>
58    <td>b.jpg</td>
59  </tr>
60  <tr>
61    <td align="center"><input type="checkbox" name="files[]" value="c.docx" /></td>
62    <td align="center"><img src="files/doc.png" title="Document" width="16" height="16" /></td>
63    <td>c.docx</td>
64  </tr>
65  <tr>
66    <td align="center"><input type="checkbox" name="files[]" value="d.pdf" /></td>
67    <td align="center"><img src="files/pdf.png" title="pdf" width="16" height="16" /></td>
68    <td>d.pdf</td>
69  </tr>
70  <tr>
71    <td colspan="3" align="center">
72        <input type="submit" name="createpdf" style="border:0px; background-color:#800040; color:#FFF; padding:10px; cursor:pointer; font-weight:bold; border-radius:5px;" value="Download as ZIP" /> 
73        <input type="reset" name="reset" style="border:0px; background-color:#D3D3D3; color:#000; font-weight:bold; padding:10px; cursor:pointer; border-radius:5px;" value="Reset" />
74    </td>
75    </tr>
76</table>
77
78</form>
79</body>
80</html>
queries leading to this page
php ziparchive installinstall php ziparchivephp crete zipphp put files into zipziparchive php 7ziparchive php 7 2ziparchive in phpphp create zip filephp ziparchive openzip in phpziparchive phpphp update a file inside zipzip a php filezip archieve in phpphp create zipzip formate phpmake zip file in phphow to archive in phpphp 7 zip archiveziparchive 28 29ziparchive php tutophp zipphp zip fileszip file function in phpcreate zip file in phpphp zip file creationziparchive php exampleziparchive enable phpphp ziparchive zip all zip filesziparchive 2b php inizip en php avec ziparchivenew ziparchive phpzip file in php php generate zip fileziparchive php downloadphp how to make new zip filephp zipachrivephp ziparchive create zip filephp ziparchive tutorialuse ziparchive phpphp zip functionphp adding lots of big files to zipcreate zip with phpphp zip filephp new ziparchive 28 29how to use ziparchive in phpziparchive in php iniphp new ziparchiveziparchive 28 29 phpphp install zip extensionphp 24zip 3d new ziparchive 28 29 3bphp ziparchive examplephp ziparchive sozip files phpphp test ziparchive using cliziparchive php parametersphp zip archivecreate zip file with phpphp ziparchive return zip filephp ziparchive zip only zip filesphp zip a filezip archive phparchive 3d 1 in phphow to zip a file in phpcreate zip fil in phphow zip a file in phpzip file php examplescaricarre file zip phpphp zip archive and emailcreate a zip of files in phpphp ziparchivegenereta zip phpziparchive php example