rahuul Posted March 17, 2010 Share Posted March 17, 2010 how can we make rar files in php...... like i have 2 files: 1.doc, 2.doc i want to add both file in 3.rar or 3.zip pls help Quote Link to comment Share on other sites More sharing options...
Wolphie Posted March 17, 2010 Share Posted March 17, 2010 This should work <?php function archive($files = array(), $destination = '', $overwrite = FALSE) { if (file_exists($destination) && !$overwrite) { return false; } $valid_files = array(); if (is_array($files)) { foreach ($files as $file) { if (file_exists($file)) { $valid_files[] = $file; } } } if (count($valid_files)) { $zip = new ZipArchive(); if ($overwrite) { $zipcreate = $zip->open($destination, ZIPARCHIVE::OVERWRITE); } else { $zipcreate = $zip->open($destination, ZIPARCHIVE::CREATE); } if ($zipcreate !== TRUE) { return FALSE; } $zip->close(); return file_exists($destination); } else { return FALSE; } } // Example $files_to_zip = array('images/1.png', 'images/2.png', 'read.jpg'); $result = archive($files_to_zip, 'my_archive.zip'); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.