Location: PHPKode > projects > StreamOnTheFly > node/www/getFile.php
<?php // -*- tab-width: 3; indent-tabs-mode: 1; -*- 

/*  
 * $Id: getFile.php,v 1.16 2005/02/01 14:17:40 micsik Exp $
 * Created for the StreamOnTheFly project (IST-2001-32226)
 * Authors: András Micsik, Máté Pataki, Tamás Déri 
 *          at MTA SZTAKI DSD, http://dsd.sztaki.hu
 */

require("init.inc.php");

$filename = sotf_Utils::getParameter('filename');
if(!$filename)
  $filename = sotf_Utils::getParameter('f');
$id = sotf_Utils::getParameter('id');
$fid = sotf_Utils::getParameter('fid');
$mainAudio = sotf_Utils::getParameter('audio');

if(empty($fid)) {
  if(empty($id)) {
	 raiseError("Missing parameters!", 'id');
  }
  if(empty($filename)) {
	 raiseError("Missing parameters!", 'filename');
  }
}

if($fid) {
  $fobj = &$repository->getObject($fid);
  if(!$fobj)
	 raiseError("no_such_object", $fid);
  $prg = $repository->getObject($fobj->get('prog_id'));
  $mainAudio = $fobj->get('main_content') == 't';
  $filename = $fobj->get('filename');
} else {
  $prg = $repository->getObject($id);
}

if(!$prg)
  raiseError("no_such_object", $id);

if(!$prg->isLocal()) {
  // have to send user to home node of this programme
  sotf_Node::redirectToHomeNode($prg, 'getFile.php');
  exit;
}

// TODO check if user have rights to access: 1. prg is published, 2. file has public_access or donwload_access

if($mainAudio)
     $filename =  sotf_Utils::getFileInDir($prg->getAudioDir(), $filename);
else
     $filename =  sotf_Utils::getFileInDir($prg->getOtherFilesDir(), $filename);

if(!is_readable($filename))
  raiseError("File not readable", $filename);

debug('filename', $filename);

$file = & new sotf_File($filename);
if ($file->type != "none")
{
	header("Content-type: " . $file->mimetype . "\n");
	header("Content-length: " . filesize($filename) . "\n");   
	//if($mainAudio) {  //this is somehow needed for iPodder
	//  header("Accept-Ranges: bytes");
	//  header('ETag: "' . md5(file_get_contents($filename)) . '"');
	//} else {
	  header("Content-transfer-encoding: binary\n"); 
	  //}
	// send file
	readfile($filename);
}
else
  raiseError("download_problem", $filename);

// add this download to statistics
$prg->addStat($file->id, "downloads");


$page->logRequest();

?>
Return current item: StreamOnTheFly