3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php // Get folder name $folder = $params['folder']; $zipFolder = $folder . '.zip'; // Get instance of ZipArchive $zipArchive = new ZipArchive(); // Open zip archive $zipArchive->open($zipFolder, ZIPARCHIVE::CREATE); $zipArchive->addEmptyDir($folder); //zipFolderFiles($folder, $zipArchive); // Close zip archive $zipArchive->close(); // Download archive header('Content-Type: application/zip'); header('Content-disposition: attachment; filename=' . $zipFolder); header('Content-Length: ' . filesize($zipFolder)); readfile($zipFolder); // Recursive zip creation function function zipFolderFiles($dir, &$zipArchive) { //$base_path = './uploads/tenders/'; //$ffs = scandir($base_path . $dir); //if (!is_array($ffs) || empty($ffs)) return; //foreach ($ffs as $ff) { // if ($ff != '.' && $ff != '..') { // if (is_dir($base_path . $dir . '/' . $ff)) { // $zipArchive->addEmptyDir($ff); // zipFolderFiles($dir . '/' . $ff, $zipArchive); // } else { // $zipArchive->addFile($base_path . $dir . '/' . $ff, $ff); // } // } //} }
Output for 7.0.0 - 7.2.0
Notice: Undefined variable: params in /in/quReB on line 4 Fatal error: Uncaught Error: Class 'ZipArchive' not found in /in/quReB:8 Stack trace: #0 {main} thrown in /in/quReB on line 8
Process exited with code 255.
Output for 5.0.4 - 5.1.6, 5.4.0 - 5.6.28
Notice: Undefined variable: params in /in/quReB on line 4 Fatal error: Class 'ZipArchive' not found in /in/quReB on line 8
Process exited with code 255.
Output for 5.2.3 - 5.3.29
Notice: Undefined variable: params in /in/quReB on line 4 Warning: Cannot modify header information - headers already sent by (output started at /in/quReB:4) in /in/quReB on line 19 Warning: Cannot modify header information - headers already sent by (output started at /in/quReB:4) in /in/quReB on line 20 Warning: filesize(): stat failed for .zip in /in/quReB on line 21 Warning: Cannot modify header information - headers already sent by (output started at /in/quReB:4) in /in/quReB on line 21 Warning: readfile(.zip): failed to open stream: No such file or directory in /in/quReB on line 22
Output for 5.2.1 - 5.2.2
Notice: Undefined variable: params in /in/quReB on line 4 Warning: filesize(): stat failed for .zip in /in/quReB on line 21 Warning: readfile(.zip): failed to open stream: No such file or directory in /in/quReB on line 22
Output for 5.2.0
Notice: Undefined variable: params in /in/quReB on line 4 Fatal error: Call to undefined method ZipArchive::addEmptyDir() in /in/quReB on line 12
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: params in /in/quReB on line 4 Fatal error: Class 'ZipArchive' not found in /in/quReB on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected ')', expecting '(' in /in/quReB on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected ')', expecting '(' in /in/quReB on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `'('' in /in/quReB on line 11
Process exited with code 255.