/** * Public interface for adding a dir and its contents recursively to zip file * @access public * @param string $dir the real system directory that contains the files to add to the zip * @param string $zip_prefix_dir the zip dir where the contents of $dir will be put in * @param string $pre_pend_dir used during the recursion to keep track of the path, default='' * @see $_base_path in include/vitals.inc.php * @see priv_add_dir() in include/classes/zipfile.class.php * @see add_file() in include/classes/zipfile.class.php * @author Joel Kronenberg */ function add_dir($dir, $zip_prefix_dir, $pre_pend_dir = '') { if (!($dh = @opendir($dir . $pre_pend_dir))) { echo 'cant open dir: ' . $dir . $pre_pend_dir; exit; } //copy folder recursively into the temp folder. FileUtility::copys($dir, $this->zipfile_dir . DIRECTORY_SEPARATOR . $zip_prefix_dir); }
/** * Allows the copying of entire directories. * @access public * @param string $source the source directory * @param string $dest the destination directory * @return boolean whether the copy was successful or not * @link http://www.php.net/copy * @author www at w8c dot com */ public static function copys($source, $dest) { if (!is_dir($source)) { return false; } if (!is_dir($dest)) { mkdir($dest); } $h = @dir($source); while (@($entry = $h->read()) !== false) { if ($entry == '.' || $entry == '..') { continue; } if (is_dir("{$source}/{$entry}") && $dest !== "{$source}/{$entry}") { FileUtility::copys("{$source}/{$entry}", "{$dest}/{$entry}"); } else { @copy("{$source}/{$entry}", "{$dest}/{$entry}"); } } $h->close(); return true; }
print_progress($step); /* try copying the content over from the old dir to the new one */ require '../include/classes/FileUtility.class.php'; // for copys() $content_dir = urldecode(trim($_POST['step4']['content_dir'])); $_POST['step4']['copy_from'] = urldecode(trim($_POST['step4']['copy_from'])) . DIRECTORY_SEPARATOR; //copy if copy_from is not empty if ($_POST['step4']['copy_from'] && $_POST['step4']['copy_from'] != DIRECTORY_SEPARATOR) { if (is_dir($_POST['step4']['copy_from'])) { $files = scandir($_POST['step4']['copy_from']); foreach ($files as $file) { if ($file == '.' || $file == '..') { continue; } if (is_dir($_POST['step4']['copy_from'] . $file)) { FileUtility::copys($_POST['step4']['copy_from'] . $file, $content_dir . $file); if (is_dir($content_dir . $course)) { $progress[] = 'Course content directory <b>' . $file . '</b> copied successfully.'; } else { $errors[] = 'Course content directory <b>' . $file . '</b> <strong>NOT</strong> copied.'; } } else { // a regular file copy($_POST['step4']['copy_from'] . $file, $content_dir . $file); } } } } else { $progress[] = 'Using existing content directory <strong>' . $content_dir . '</strong>.'; } if (isset($progress)) {