Skip to content
Snippets Groups Projects
Commit 18e13353 authored by Naszlady Márton Bese's avatar Naszlady Márton Bese
Browse files

Implemented image fetching from db.

parent 8d887fab
No related branches found
No related merge requests found
<?php <?php
ob_start("ob_gzhandler"); // Example url:
// http://kibusam.itk.ppke.hu/image.php?thumbnail&1190
require('./core/backend.php');
$username = $_SESSION['user'];
$uri = $_SERVER['QUERY_STRING']; $uri = $_SERVER['QUERY_STRING'];
$uri_parts = explode('&',$uri); $uri_parts = explode('&',$uri);
$path = "/home/hakta/public_html/belepteto/images/".$uri_parts[0]; $path = "/home/hakta/public_html/belepteto/images/".$uri_parts[0];
header('Content-type: image/jpeg'); if(!in_array($uri_parts[0], array('thumbnail', 'photo'))) {
header('Accept-Ranges: bytes'); die('Not valid request!');
}
$pic_ID = intval($uri_parts[1]);
if($uri_parts[0] == "thumbnail") {
$result = $db->prepare('
SELECT thumbnail_img
FROM thumbnail t
INNER JOIN annotation a ON a.thumbnail_ID = t.thumbnail_ID
INNER JOIN user u ON u.card_ID = a.card_ID
WHERE t.thumbnail_ID=:picid AND u.name=:username');
$result->execute(array('username' => $username, 'picid' => $pic_ID));
$result = $result->fetch(PDO::FETCH_NUM);
if($result[0]) {
header('Content-type: image/jpeg');
die($result[0]);
}
} elseif ($uri_parts[0] == "photo") {
$result = $db->prepare('
SELECT photo_img
FROM photo p
INNER JOIN thumbnail t ON p.photo_ID = t.photo_ID
INNER JOIN annotation a ON a.thumbnail_ID = t.thumbnail_ID
INNER JOIN user u ON u.card_ID = a.card_ID
WHERE t.thumbnail_ID=:picid AND u.name=:username');
$result->execute(array('username' => $username, 'picid' => $pic_ID));
$result = $result->fetch(PDO::FETCH_NUM);
if($result[0]) {
header('Content-type: image/jpeg');
die($result[0]);
}
}
exit;
//header('Content-type: image/jpeg');
//header('Accept-Ranges: bytes');
//header('Content-Length: ' . filesize($path)); //header('Content-Length: ' . filesize($path));
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($path)).' GMT'); //header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($path)).' GMT');
$seconds_to_cache = 31536000; //header('Expires: '.gmdate('D, d M Y H:i:s', time()+$seconds_to_cache).' GMT');
header('Expires: '.gmdate('D, d M Y H:i:s', time()+$seconds_to_cache).' GMT'); //header('Pragma: cache');
header('Pragma: cache'); //header('Cache-Control: max-age='.$seconds_to_cache);
header('Cache-Control: max-age='.$seconds_to_cache); //header('Vary: Accept-Encoding');
header('Vary: Accept-Encoding');
//header('Content-Encoding: gzip'); //header('Content-Encoding: gzip');
header_remove('x-powered-by'); //header_remove('x-powered-by');
\ No newline at end of file
//readfile($path);die();
$image=imagecreatefromjpeg($path);
if (count($uri_parts) > 1) {
list($width, $height) = getimagesize($path);
$new_width = (int)$uri_parts[1];
$new_height = $new_width / $width * $height;
$tmp = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
} else {
$tmp = $image;
}
imagejpeg($tmp, NULL, 85);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment