Basically I'm trying to compress a directory from a relative path using the Joomla JArchive::create()
function. So far I can zip a directory but it zips the entire absolute path.
The code I am using that zip the absolute path is as shown below:
$zipFilesArray = array();
$new_component_path = JPATH_SITE.'/'.'modules'.'/'.'mod_module_gen'.'/'.'package'.'/'.$new_folder_name;
$dirs = JFolder::folders($new_component_path, '.', true, true);
array_push($dirs, $new_component_path);
foreach ($dirs as $dir) {
$files = JFolder::files($dir, '.', false, true);
foreach ($files as $file) {
$data = JFile::read($file);
$zipFilesArray[] = array('name' => str_replace($new_component_path.DS, '', $file), 'data' => $data);
}
}
$zip = JArchive::getAdapter('zip');
$zip->create($new_component_path.'/'.$new_folder_name.'.zip', $zipFilesArray);
I think is has something to do with using the JPATH_SITE
structure which I have tried changing to the JURI::root
structure but then provides an error saying that its not a valid path.
I anyone could tell me how to zip relative path in Joomla based on the code I have provided then this would be much appreciated.