コード例 #1
0
/**
 * archives a folder into a specified zip handler.
 *
 * $folder_id the ID of the folder to archive recursively, with content.
 * $zipfile reference to the zipFile object.
 * $path the absolute path to the current folder.
 */
function fs_download_folder($folder_id, &$zipfile, $owner_type, $owner_id, $path = '') {
	global $db;

	$parent_row = fs_get_folder_by_id($folder_id, $owner_type, $owner_id);
	//$sql = "SELECT title FROM ".TABLE_PREFIX."folders WHERE folder_id=$folder_id AND owner_type=$owner_type AND owner_id=$owner_id";
	//$result = mysql_query($sql, $db);
	if ($parent_row) {
		$zipfile->create_dir($path . $parent_row['title']);
	}

	$sql = "SELECT file_id, file_name, UNIX_TIMESTAMP(date) AS date FROM ".TABLE_PREFIX."files WHERE folder_id=$folder_id AND parent_file_id=0 AND owner_type=$owner_type AND owner_id=$owner_id";
	$result = mysql_query($sql, $db);
	while ($row = mysql_fetch_assoc($result)) {
		$file_path = fs_get_file_path($row['file_id']) . $row['file_id'];

		$zipfile->add_file(file_get_contents($file_path), $path . $parent_row['title'] .'/' . $row['file_name'], $row['date']);
	}

	$rows = fs_get_folder_by_pid($folder_id, $owner_type, $owner_id);
	foreach ($rows as $row) {
		fs_download_folder($row['folder_id'], $zipfile, $owner_type, $owner_id, $path . $parent_row['title'] . '/');
	}
}
コード例 #2
0
ファイル: index.php プロジェクト: vicentborja/ATutor
     $zip_file_name = fs_get_workspace($owner_type, $owner_id);
     // want the name of the workspace
     $zip_file_name = str_replace(" ", "_", $zip_file_name);
     if (is_array($_GET['files'])) {
         foreach ($_GET['files'] as $file_id) {
             $file_path = fs_get_file_path($file_id) . $file_id;
             $sql = "SELECT file_name, UNIX_TIMESTAMP(date) AS date FROM " . TABLE_PREFIX . "files WHERE file_id={$file_id} AND owner_type={$owner_type} AND owner_id={$owner_id}";
             $result = mysql_query($sql, $db);
             if (($row = mysql_fetch_assoc($result)) && file_exists($file_path)) {
                 $zipfile->add_file(file_get_contents($file_path), $row['file_name'], $row['date']);
             }
         }
     }
     if (is_array($_GET['folders'])) {
         foreach ($_GET['folders'] as $folder_id) {
             fs_download_folder($folder_id, $zipfile, $owner_type, $owner_id);
             $row['title'] = str_replace(" ", "_", $row['title']);
             $zipfile->create_dir($row['title']);
         }
         if (count($_GET['folders']) == 1) {
             // zip just one folder, use that folder's title as the zip file name
             $row = fs_get_folder_by_id($_GET['folders'][0], $owner_type, $owner_id);
             if ($row) {
                 $zip_file_name = $row['title'];
                 $zip_file_name = str_replace(" ", "_", $zip_file_name);
             }
         }
     }
     $zipfile->close();
     $zipfile->send_file($zip_file_name);
 }
コード例 #3
0
/**
 * archives a folder into a specified zip handler.
 *
 * $folder_id the ID of the folder to archive recursively, with content.
 * $zipfile reference to the zipFile object.
 * $path the absolute path to the current folder.
 */
function fs_download_folder($folder_id, &$zipfile, $owner_type, $owner_id, $path = '')
{
    $parent_row = fs_get_folder_by_id($folder_id, $owner_type, $owner_id);
    if ($parent_row) {
        $zipfile->create_dir($path . $parent_row['title']);
    }
    $sql = "SELECT file_id, file_name, UNIX_TIMESTAMP(date) AS date FROM %sfiles WHERE folder_id=%d AND parent_file_id=0 AND owner_type=%d AND owner_id=%d";
    $rows_files = queryDB($sql, array(TABLE_PREFIX, $folder_id, $owner_type, $owner_id));
    foreach ($rows_files as $row) {
        $file_path = fs_get_file_path($row['file_id']) . $row['file_id'];
        $zipfile->add_file(file_get_contents($file_path), $path . $parent_row['title'] . '/' . $row['file_name'], $row['date']);
    }
    $rows = fs_get_folder_by_pid($folder_id, $owner_type, $owner_id);
    foreach ($rows as $row) {
        fs_download_folder($row['folder_id'], $zipfile, $owner_type, $owner_id, $path . $parent_row['title'] . '/');
    }
}