__normalizePath(realpath($basepath)); $src_realpath = $this->__normalizePath(realpath($srcpath)); $search_index = strpos($src_realpath, $base_realpath); if($search_index === 0) { $startindex = strlen($base_realpath)+1; // On windows $base_realpath ends with / and On Linux it will not have / at end! if(strrpos($base_realpath, '/') == strlen($base_realpath)-1) $startindex -= 1; $relpath = substr($src_realpath, $startindex); } return $relpath; } /** * Check and add '/' directory separator */ function __fixDirSeparator($path) { if($path != '' && (strripos($path, '/') != strlen($path)-1)) $path .= '/'; return $path; } /** * Normalize the directory path separators. */ function __normalizePath($path) { if($path && strpos($path, '\\')!== false) $path = preg_replace("/\\\\/", "/", $path); return $path; } /** * Copy the directory on the disk into zip file. */ function copyDirectoryFromDisk($dirname, $zipdirname=null, $excludeList=null, $basedirname=null) { $dir = opendir($dirname); if(strripos($dirname, '/') != strlen($dirname)-1) $dirname .= '/'; if($basedirname == null) $basedirname = realpath($dirname); while(false !== ($file = readdir($dir))) { if($file != '.' && $file != '..' && $file != '.svn' && $file != 'CVS') { // Exclude the file/directory if(!empty($excludeList) && in_array("$dirname$file", $excludeList)) continue; if(is_dir("$dirname$file")) { $this->copyDirectoryFromDisk("$dirname$file", $zipdirname, $excludeList, $basedirname); } else { $zippath = $dirname; if($zipdirname != null && $zipdirname != '') { $zipdirname = $this->__fixDirSeparator($zipdirname); $zippath = $zipdirname.$this->__getRelativePath($basedirname, $dirname); } $this->copyFileFromDisk($dirname, $zippath, $file); } } } closedir($dir); } /** * Copy the disk file into the zip. */ function copyFileFromDisk($path, $zippath, $file) { $path = $this->__fixDirSeparator($path); $zippath = $this->__fixDirSeparator($zippath); $this->addFile("$path$file", "$zippath$file"); } } ?>