/**
 * 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'] . '/');
	}
}
Example #2
0
$cols = array('file_name' => 1, 'file_size' => 1, 'date' => 1);
if (isset($_GET['asc'])) {
    $order = 'asc';
    $col = isset($cols[$_GET['asc']]) ? $_GET['asc'] : 'file_name';
} else {
    if (isset($_GET['desc'])) {
        $order = 'desc';
        $col = isset($cols[$_GET['desc']]) ? $_GET['desc'] : 'file_name';
    } else {
        // no order set
        $order = 'asc';
        $col = 'file_name';
    }
}
$folder_path = fs_get_folder_path($folder_id, $owner_type, $owner_id);
$folders = fs_get_folder_by_pid($folder_id, $owner_type, $owner_id);
$files = array();
$sql = "SELECT * FROM " . TABLE_PREFIX . "files WHERE folder_id={$folder_id} AND owner_type={$owner_type} AND owner_id={$owner_id} AND parent_file_id=0 ORDER BY {$col} {$order}";
$result = mysql_query($sql, $db);
while ($row = mysql_fetch_assoc($result)) {
    $files[] = $row;
}
?>

<?php 
if (query_bit($owner_status, WORKSPACE_AUTH_WRITE)) {
    ?>
	<form method="post" action="<?php 
    echo 'mods/_standard/file_storage/index.php' . $owner_arg_prefix;
    ?>
" enctype="multipart/form-data" name="form0">
/**
 * 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'] . '/');
    }
}