<?php
	require("../__common__/__define_common.php");
	require("../__common__/include-common-all.php");
	require("../account/__logincheck.php");

	$file_name = my_GET('file').'';
	if (defined("photo_LIMITED_IMAGES_FOLDER") and photo_LIMITED_IMAGES_FOLDER <> '') {
		if ($_SESSION['システム管理者'] <> "YES" or photo_LIMITED_ADMIN_NOLIMIT <> 'YES') {
			$len = strlen(photo_LIMITED_IMAGES_FOLDER);
			if (substr($file_name, 0, $len) <> photo_LIMITED_IMAGES_FOLDER) {
				exit;
			}
		}
	}
	if ($file_name == '') {
		exit;
	}
	if ($_GET['ss'].'' <> '') {
		$opt_ss = ' -ss ' . $_GET['ss'].'';
	}
/*
	$cmd = 'ffmpeg -vframes 1 -i "'.$file_name.'" -f image2'.$opt_ss.' -';
	header("Content-Type: image/jpeg");
	@passthru(myfile_ENCODE($cmd));
*/
	$mov_thumb_file = mov_thumb_file($file_name, $_GET['ss']);
	$mov_thumb_SJIS = myfile_ENCODE($mov_thumb_file);
	if (!file_exists($mov_thumb_SJIS)) {
		exec('ffmpeg -vframes 1 -i "'.myfile_ENCODE($file_name).'" -f image2'.$opt_ss.' "'.$mov_thumb_SJIS.'"');
	}
	$fp = fopen($mov_thumb_SJIS, "rb");
	if ($fp) {
		if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
			$file_name = myfile_ENCODE(substr($file_name,strrpos($file_name,'/')+1));
		} else {
			$file_name = urlencode(substr($file_name,strrpos($file_name,'/')+1));
		}
		header('Content-type: image/jpeg');
		header('Content-Disposition: inline; filename='.$file_name);
		fpassthru($fp);
	}
function mov_thumb_file($file_name, $ss) {		// UTF-8
	$mov_thumb_dir = up_folder_path($file_name).photo_RESIZE_DIR_THUMB;
	if (!@opendir(myfile_ENCODE($mov_thumb_dir))) {
		@mkdir(myfile_ENCODE($mov_thumb_dir));
	}
	$basename = basename($file_name);
	$pos = strrpos($basename, '.');
	if ($ss.'' == '') $ss = 0;
	return ($mov_thumb_dir.left($basename,$pos).'-'.$ss.'.jpg');
}
?>
