【发布时间】:2012-06-20 11:23:56
【问题描述】:
基本上,我正在尝试使用 Joomla JArchive::create() 函数从相对路径压缩目录。到目前为止,我可以压缩一个目录,但它会压缩整个绝对路径。
我使用的那个zip的代码绝对路径如下图:
$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);
我认为这与使用 JPATH_SITE 结构有关,我尝试将其更改为 JURI::root 结构,但随后提供了一个错误,指出它不是有效路径。
任何人都可以告诉我如何根据我提供的代码在 Joomla 中压缩相对路径,我们将不胜感激。
【问题讨论】:
-
使用相对路径有什么具体原因吗?
-
@Anand:是的,因为当我使用绝对路径时,它实际上会压缩整个绝对路径,从 public_html 文件夹开始。
-
我认为 $zipFilesArray 应该是包含具有完整路径的文件的数组,而不仅仅是文件名。 $zipFilesArray 中也不需要数据
标签: joomla zip relative-path joomla2.5