Location: PHPKode > projects > Kwalbum > kwalbum/include/file.php
<?php
/**
 * Send a file to the browser based on the item and requested way of sending it.
 * @package kwalbum
 * @version 2.2
 * @since 2.1
 */
require_once 'include/verifyLogin.php';
require_once 'include/itemTypes.php';

$id = @(int)$_GET['f'];
$size = @(int)$_GET['s'];
if (0 >= $id)
	exit;

$query = 'SELECT ItemPath, ItemFilename, ItemTypeId' .
			' FROM ' . ITEM_TABLE .
			' WHERE ItemId=' . $id . (USER_IS_ADMIN ? null : (USER_CAN_VIEW_QUERY ? ' AND '.USER_CAN_VIEW_QUERY : null));
$result = $DB->Query($query);

if (0 == $result->num_rows)
{
	header('Content-Type: text/plain');
	echo 'This file may or may not exist.  Either way, you do not have permission to download it.';
	exit;
}

$row = $result->fetch_array(MYSQLI_ASSOC);
$DB->Close();

switch ($row['ItemTypeId'])
{
	case JPEG_FILE:
		header('Content-Type: image/jpeg');
		break;
	case GIF_FILE:
		header('Content-Type: image/gif');
		break;
	case PNG_FILE:
		header('Content-Type: image/x-png');
		break;
	case WMV_FILE:
		header('Content-Type: video/x-ms-wmv');
		break;
	case DIVX_FILE:
		header('Content-Type: video/x-msvideo');
		break;
	case MP4_FILE:
		header('Content-Type: video/mp4v-es');
		break;
	case MPEG_FILE:
		header('Content-Type: video/mpeg');
		break;
	case TEXT_FILE:
		header('Content-Type: text/plain');
		break;
	case XML_FILE:
	case GPX_FILE:
		header('Content-Type: text/xml');
		break;
	case HTML_FILE:
		header('Content-Type: text/html');
		break;
	case ZIP_FILE:
		header('Content-Type: application/zip');
		break;
	case ODT_FILE:
		header('Content-Type: application/vnd.oasis.opendocument.text');
		break;
	case ODS_FILE:
		header('Content-Type: application/vnd.oasis.opendocument.spreadsheet');
		break;
	case DOC_FILE:
		header('Content-Type: application/msword');
		break;
	case MP3_FILE:
		header('Content-Type: audio/mp3');
		break;
	case OGG_FILE:
		header('Content-Type: audio/x-ogg ');
		break;
	case WAV_FILE:
		header('Content-Type: audio/x-wav');
		break;
	case FLV_FILE:
		header('Content-Type: audio/x-flv');
		break;
	default:
		echo 'File type not yet downloadable.';
		exit;
}

switch ($size)
{
	case 1:
		header('Content-Disposition: inline; filename="thumbnail-'.$row['ItemFilename'].'"');
		$file = PICS_PATH.$row['ItemPath'].'t/'.$row['ItemFilename'];
		break;
	case 2:
		header('Content-Disposition: inline; filename="resized-'.$row['ItemFilename'].'"');
		$file = PICS_PATH.$row['ItemPath'].'r/'.$row['ItemFilename'];
		break;
	case 3:
		if (!empty($row['ItemFilename']));
		header('Content-Disposition: attachment; filename="'.$row['ItemFilename'].'"');
		$file = PICS_PATH.$row['ItemPath'].$row['ItemFilename'];
		break;
	default:
		header('Content-Disposition: inline; filename="'.$row['ItemFilename'].'"');
		$file = PICS_PATH.$row['ItemPath'].$row['ItemFilename'];
		break;
}

header('Content-Length: '.filesize($file));
readfile($file);
exit;
Return current item: Kwalbum