function fm_zip_files($originalfiles, $destination, $zipname = "zip01", $rootdir = 0, $groupid = 0) { //Zip an array of files/dirs to a destination zip file //Both parameters must be FULL paths to the files/dirs // Modded for Myfiles // Michael Avelar 1/19/06 global $CFG, $USER; //Extract everything from destination $path_parts = pathinfo(cleardoubleslashes($destination)); $destpath = $path_parts['dirname']; //The path of the zip file $destfilename = $path_parts['basename']; //The name of the zip file // To put the zipped file into the current directory $destpath = $destpath . "/" . $destfilename; // To allow naming of zipfiles $destfilename = $zipname; //If no file, error if (empty($destfilename)) { return false; } //If no extension, add it if (empty($path_parts['extension'])) { $extension = 'zip'; $destfilename = $destfilename . '.' . $extension; } else { $extension = $path_parts['extension']; //The extension of the file } //Check destination path exists if (!is_dir($destpath)) { return false; } //Check destination path is writable. TODO!! //Clean destination filename $destfilename = clean_filename($destfilename); //Now check and prepare every file $files = array(); $origpath = NULL; foreach ($originalfiles as $file) { //Iterate over each file //Check for every file $tempfile = cleardoubleslashes($file); // no doubleslashes! //Calculate the base path for all files if it isn't set if ($origpath === NULL) { $origpath = rtrim(cleardoubleslashes(dirname($tempfile)), "/"); } //See if the file is readable if (!is_readable($tempfile)) { //Is readable continue; } //See if the file/dir is in the same directory than the rest if (rtrim(cleardoubleslashes(dirname($tempfile)), "/") != $origpath) { continue; } //Add the file to the array $files[] = $tempfile; } //Everything is ready: // -$origpath is the path where ALL the files to be compressed reside (dir). // -$destpath is the destination path where the zip file will go (dir). // -$files is an array of files/dirs to compress (fullpath) // -$destfilename is the name of the zip file (without path) //print_object($files); //Debug if (empty($CFG->zip)) { // Use built-in php-based zip function include_once "{$CFG->libdir}/pclzip/pclzip.lib.php"; $archive = new PclZip(cleardoubleslashes("{$destpath}/{$destfilename}")); if ($list = $archive->create($files, PCLZIP_OPT_REMOVE_PATH, $origpath) == 0) { notice($archive->errorInfo(true)); return false; } } else { // Use external zip program $filestozip = ""; foreach ($files as $filetozip) { $filestozip .= escapeshellarg(basename($filetozip)); $filestozip .= " "; } //Construct the command $separator = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? ' &' : ' ;'; $command = 'cd ' . escapeshellarg($origpath) . $separator . escapeshellarg($CFG->zip) . ' -r ' . escapeshellarg(cleardoubleslashes("{$destpath}/{$destfilename}")) . ' ' . $filestozip; //All converted to backslashes in WIN if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $command = str_replace('/', '\\', $command); } Exec($command); } // Adds an entry into myfiles api $newentry = NULL; if ($groupid == 0) { $newentry->owner = $USER->id; } else { $newentry->owner = $groupid; } $newentry->type = TYPE_ZIP; $newentry->folder = $rootdir; $newentry->category = 0; $newentry->name = substr($destfilename, 0, -4); $newentry->description = ''; $newentry->link = $destfilename; $newentry->timemodified = time(); if (!fm_update_link($newentry, $groupid)) { error(get_string("errnoupdate", 'block_file_manager')); } return true; }
$dupfile = true; $missinginput['link'] = true; } } } if (isset($_POST['change'])) { if ($store->name == '' || $store->radioval == 'url' && $store->url == '') { // verify's input notify(get_string('msgneedinputname', 'block_file_manager')); } else { if ($groupid == 0) { fm_user_owns_link($linkid); } else { fm_group_owns_link($linkid, $groupid); } fm_update_link($store, $groupid, $linkid, $id, $rootdir); notify(get_string('msgmodificationok', 'block_file_manager'), 'notifysuccess'); if (!$popup) { redirect("view.php?id={$id}&groupid={$groupid}&rootdir={$rootdir}"); } else { redirect("link_manage.php?id={$id}&groupid={$groupid}&popup=close&rootdir={$rootdir}"); } } } if ($linkid != NULL) { // Modding existing link if ($groupid == 0) { fm_user_owns_link($linkid); } else { fm_group_owns_link($linkid, $groupid); }