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 Link to comment https://forums.phpfreaks.com/topic/195564-rar-file-in-php/ 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'); ?> Link to comment https://forums.phpfreaks.com/topic/195564-rar-file-in-php/#findComment-1027639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.