display_image.php 1.73 KB
<?php
/**
 * $Id: display_image.php
 * @author g_wang
 * @access public
 * @package www
 */
require_once ("user_include.inc");

// パラメータを取得
$type = ParamUtil::getRequestString("type");
$child_path = ParamUtil::getRequestString("child_path");//不包含"/"
$file_name = ParamUtil::getRequestString("file_name");

$file_path = IMAGES_PATH;
if ($type == "theme") {
	$file_path = THEME_IMAGES_PATH;
	if(!empty($child_path)) {
		$file_path .= "/" . $child_path;
	}
	$file_path .= "/" . $file_name;
} else if ($type == "article") {
	$file_path = ARTICLE_IMAGES_PATH;
	if(!empty($child_path)) {
		$file_path .= "/" . $child_path;
	}
	$file_path .= "/" . $file_name;
} else if ($type == "category") {
	$file_path = ARTICLE_IMAGES_PATH;
	if(!empty($child_path)) {
		$file_path .= "/" . $child_path;
	}
	$file_path .= "/" . $file_name;
} else if ($type == "course") {
	$file_path = COURSE_IMAGES_PATH;
	if(!empty($child_path)) {
		$file_path .= "/" . $child_path;
	}
	$file_path .= "/" . $file_name;
} else if ($type == "video") {
	$file_path = VIDEO_PATH;
	$file_path .= "/" . $file_name;
} else {
	if(!empty($child_path)) {
		$file_path .= "/" . $child_path;
	}
	$file_path .= "/" . $file_name;
}

if (file_exists($file_path)) {
	header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
	header("Cache-Control: post-check=0, pre-check=0", false);
	header("Pragma: no-cache");                 // HTTP/1.0

	$handle = fopen($file_path, "rb");
	$image_data = fread($handle, filesize($file_path));
	$size = getimagesize($file_path);
	header("Content-type: " . $size["mime"]);
	header("Content-length: " . strlen($image_data));
	print $image_data;
	fclose($handle);
	exit;
}

header("HTTP/1.0 404 Not Found");
header("Status: 404 Not Found");
exit;