My website current is serving images on the same server and I wanna take out this load to serve bu other server. I am currently putting all the image outside root folder and use readfile method to get and display the image. As you can see below script, I will check the $_SESSION['message_owner_id'] session variable. Is it possible to propagate this session variable to another server?
Code: Select all
<?php
session_start();
if(!isset($_SESSION['message_owner_id'])){
die('<strong>Your session has expired!</strong>');
}
$file = strtolower($_GET['f']);
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
if(endswith($file, 'jpg') || endswith($file, 'png') || endswith($file, 'gif') || endswith($file, 'tif') || endswith($file, 'tiff') || endswith($file, 'bmp')){
header('Content-type:image');
header('Content-Disposition: inline; filename="' . $file . '"');
} else {
// We'll be outputting a other format to prompt user to download
header('Content-type: application');
// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="' . $file . '"');
}
$file = '/var/upload/images/' . $_SESSION['message_owner_id'] . '_' . $file;
if(!file_exists($file)){
echo 'Opps, file cannot be found!';
return;
}
// The PDF source is in original.pdf
readfile($file);
function endswith($string, $test) {
//$strlen = strlen($string);
$testlen = strlen($test);
//if ($testlen > $strlen) return false;
return substr_compare($string, $test, -$testlen) === 0;
}
?>Mark