CC-2317: Once uploaded, file size is different than original.

This commit is contained in:
Martin Konecny 2011-05-24 16:33:26 -04:00
parent ac952ad71e
commit 28a609c4dd
1 changed files with 51 additions and 50 deletions

View File

@ -19,16 +19,16 @@ class ApiController extends Zend_Controller_Action
// action body // action body
} }
/** /**
* Returns Airtime version. i.e "1.7.0 alpha" * Returns Airtime version. i.e "1.7.0 alpha"
* *
* First checks to ensure the correct API key was * First checks to ensure the correct API key was
* supplied, then returns AIRTIME_VERSION as defined * supplied, then returns AIRTIME_VERSION as defined
* in application/conf.php * in application/conf.php
* *
* @return void * @return void
* *
*/ */
public function versionAction() public function versionAction()
{ {
global $CC_CONFIG; global $CC_CONFIG;
@ -40,20 +40,20 @@ class ApiController extends Zend_Controller_Action
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"])) if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.'; print 'You are not allowed to access this resource.';
exit; exit;
} }
$jsonStr = json_encode(array("version"=>AIRTIME_VERSION)); $jsonStr = json_encode(array("version"=>AIRTIME_VERSION));
echo $jsonStr; echo $jsonStr;
} }
/** /**
* Allows remote client to download requested media file. * Allows remote client to download requested media file.
* *
* @return void * @return void
* The given value increased by the increment amount. * The given value increased by the increment amount.
*/ */
public function getMediaAction() public function getMediaAction()
{ {
global $CC_CONFIG; global $CC_CONFIG;
@ -67,9 +67,9 @@ class ApiController extends Zend_Controller_Action
if(!in_array($api_key, $CC_CONFIG["apiKey"])) if(!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.'; print 'You are not allowed to access this resource.';
exit; exit;
} }
$filename = $this->_getParam("file"); $filename = $this->_getParam("file");
@ -80,39 +80,40 @@ class ApiController extends Zend_Controller_Action
$filepath = $media->getRealFilePath(); $filepath = $media->getRealFilePath();
if(!is_file($filepath)) if(!is_file($filepath))
{ {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
//print 'Resource in database, but not in storage. Sorry.'; //print 'Resource in database, but not in storage. Sorry.';
exit; exit;
} }
// !! binary mode !!
$fp = fopen($filepath, 'rb');
// possibly use fileinfo module here in the future. // possibly use fileinfo module here in the future.
// http://www.php.net/manual/en/book.fileinfo.php // http://www.php.net/manual/en/book.fileinfo.php
$ext = pathinfo($filename, PATHINFO_EXTENSION); $ext = pathinfo($filename, PATHINFO_EXTENSION);
if ($ext == "ogg") if ($ext == "ogg")
header("Content-Type: audio/ogg"); header("Content-Type: audio/ogg");
else if ($ext == "mp3") else if ($ext == "mp3")
header("Content-Type: audio/mpeg"); header("Content-Type: audio/mpeg");
if ($download){ if ($download){
header('Content-Disposition: attachment; filename="'.$media->getName().'"'); header('Content-Disposition: attachment; filename="'.$media->getName().'"');
}
header("Content-Length: " . filesize($filepath));
//flush the file contents 16 KBytes at a time. In the future we may
//want to use the "X-Sendfile header" method instead.
while (!feof($fp)) {
echo fread($fp, 64*1024);
ob_end_flush();
} }
header("Content-Length: " . filesize($filepath));
// !! binary mode !!
$fp = fopen($filepath, 'rb');
//We can have multiple levels of output buffering. Need to
//keep looping until all have been disabled!!!
//http://www.php.net/manual/en/function.ob-end-flush.php
while (@ob_end_flush());
fpassthru($fp);
fclose($fp); fclose($fp);
return; return;
} }
} }
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
exit; exit;
} }
public function liveInfoAction() public function liveInfoAction()
@ -261,9 +262,9 @@ class ApiController extends Zend_Controller_Action
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"])) if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.'; print 'You are not allowed to access this resource.';
exit; exit;
} }
$today_timestamp = date("Y-m-d H:i:s"); $today_timestamp = date("Y-m-d H:i:s");
@ -288,9 +289,9 @@ class ApiController extends Zend_Controller_Action
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"])) if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.'; print 'You are not allowed to access this resource.';
exit; exit;
} }
$upload_dir = ini_get("upload_tmp_dir"); $upload_dir = ini_get("upload_tmp_dir");
@ -350,9 +351,9 @@ class ApiController extends Zend_Controller_Action
$api_key = $this->_getParam('api_key'); $api_key = $this->_getParam('api_key');
if (!in_array($api_key, $CC_CONFIG["apiKey"])) if (!in_array($api_key, $CC_CONFIG["apiKey"]))
{ {
header('HTTP/1.0 401 Unauthorized'); header('HTTP/1.0 401 Unauthorized');
print 'You are not allowed to access this resource.'; print 'You are not allowed to access this resource.';
exit; exit;
} }
$md = $this->_getParam('md'); $md = $this->_getParam('md');