Jump to content

caching an image served via a php file


acctman

Recommended Posts

hi i'm using an image file php file to serve images to users how can i set it to cache the image on the users computer until it is renewed with a new image?

 

example of image link .. /files/pvtexp.php?mid=39&iid=56390&idat=2005/02&sec=3

 

I would like to add a code to the profile.php page that displays the pvtexp.php image file so that if the image iid=56390 or the link in full has changed then get the new image, if not load the cache from the users computer if available.

Link to comment
https://forums.phpfreaks.com/topic/154378-caching-an-image-served-via-a-php-file/
Share on other sites

How is the image "renewed" is it per visit or is it rotating on a timer like function, does it change out on the hour?

 

I would suggest a little bit of a mod using sessions or cookies.. set a session variable within what ever "Renews" the image, Then where the image is actually viewed have it call that session out and use the variable from the session to identify and display the image accordingly.

 

Have the page geneally check the session to see if there is a new one since the last page load and if there is have it reset the session to the new image and repeat.

How is the image "renewed" is it per visit or is it rotating on a timer like function, does it change out on the hour?

 

I would suggest a little bit of a mod using sessions or cookies.. set a session variable within what ever "Renews" the image, Then where the image is actually viewed have it call that session out and use the variable from the session to identify and display the image accordingly.

 

Have the page geneally check the session to see if there is a new one since the last page load and if there is have it reset the session to the new image and repeat.

 

everytime the user loads the page the image is retrieved

 

this is the file that retrieves the image

session_start();
$userid = $_SESSION['userid'];
if ($_GET['sec'] != 3 && $userid == '') {
header("Location: http://www.site.com");
exit;
}
ob_start();
require_once '../password.php';

if (isset($_GET['mid']) && isset($_GET['iid']) && isset($_GET['idat']) && isset($_GET['sec'])) {
$mid = $_GET['mid'];
$iid = $_GET['iid'];
$date = $_GET['idat'];

if ($_GET['sec'] == 1) { $type = "imgPvt";
$allowed = 0;
	if (intval($_SESSION['userid']) > 0) {
		if (mysql_num_rows(mysql_query("select p_id from rate_private where p_from='$mid' and p_to='" .$_SESSION['userid']. "'")) > 0 || $mid == $_SESSION['userid'] || $_SESSION['userid'] == '39') {
        $allowed = 1;
		} elseif ($allowed == 0 && $_GET['sec'] == 1) {
			header("Location: http://www.site.com");
			exit;
		}
	} 
}	
if ($_GET['sec'] == 2) { $type = "imgExp"; } 
if ($_GET['sec'] == 3) { $type = "imgPub"; }			
  	$im = @imagecreatefromjpeg('http://www.111imgs.com/'.$date.'/'.$mid.'/'.$type.'/'.($_GET['tmb']==1 ? 'imgTmb/' : '').$mid.'-'.$iid.'.jpg');
  	if(!$im) {
  		exit();
  	}
header("Content-type: image/jpeg");	
imagejpeg($im);
imagedestroy($im);					
}
$buf = ob_get_contents();
ob_end_clean();
print $buf;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.