Beispiel #1
0
<?php

/*
	7 april 2011: created from news/article.php
		and original file
*/
// get file id
$fileid = trim(@$_REQUEST['fileid']);
// instantiate download object
$download = new Download_File($fileid);
// validate it
if ($download->exists()) {
    // update the number of times it has been downloaded
    $download->incrementDownloads();
    // send file to user
    $filename = $download->get('filename');
    $fullname = TYPEF_DIR . '/files/public/downloads/' . $filename;
    if (file_exists($fullname) && is_file($fullname)) {
        header('Pragma: public');
        header('Content-Type: application/force-download');
        header('Content-Disposition: attachment; filename="' . $filename . '"');
        readfile($fullname);
        exit;
    }
}
// oops... physical file is missing...
header('HTTP/1.0 404 Not Found');
Typeframe::Redirect('File not found.', Typeframe::CurrentPage()->applicationUri(), 3, false);
Beispiel #2
0
 public static function CountDownloads($category)
 {
     // get category id
     $categoryid = $category->get('categoryid');
     // count files immediately parented to this category
     $downloads = Download_File::DAOFactory();
     Download::SetCategoryId($downloads, $categoryid);
     $count = $downloads->getTotal();
     // count children
     $subcats = Download_Category::DAOFactory();
     Download::SetParentId($subcats, $categoryid);
     foreach ($subcats->getAll() as $subcat) {
         $count += self::CountDownloads($subcat);
     }
     return $count;
 }
Beispiel #3
0
    Typeframe::Redirect('Nothing to do.', $typef_app_dir);
    return;
}
// create category with the given id
$categoryid = @$_POST['categoryid'];
$category = new Download_Category($categoryid);
// download category must exist to proceed
if (!$category->exists()) {
    Typeframe::Redirect('Invalid category specified.', $typef_app_dir, -1);
    return;
}
// make sure the category is not in use
$categories = Download_Category::DAOFactory();
$categories->select()->where('parentid = ?', $categoryid);
$catCount = $categories->getTotal();
$files = Download_File::DAOFactory();
$files->select()->where('categoryid = ?', $categoryid);
$fileCount = $files->getTotal();
if ($catCount > 0 || $fileCount > 0) {
    $message = 'Unable to delete category. It is in use by';
    $categories = 1 == $catCount ? 'category' : 'categories';
    if ($catCount > 0) {
        $message .= " {$catCount} {$categories}";
    }
    $files = 1 == $fileCount ? 'file' : 'files';
    if ($fileCount > 0) {
        $message .= ($catCount > 0 ? ' and' : '') . " {$fileCount} {$files}";
    }
    Typeframe::Redirect("{$message}.", $typef_app_dir, -1);
    return;
}