I am basically trying to compress a directory from a relative path using the Joomla JArchive::create()
function. So far I can zip the directory, but it zips the entire full path.
The code I use is that the zip absolute path is 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 this has something to do with using the JPATH_SITE
structure, which I tried to modify in the JURI::root
structure, but then provides an error saying that this is not a valid path.
I could tell me how to encode the relative path in Joomla based on the code I provided, but that would be very helpful.
source share