Outputting images with PHP - no cache?
Posted: Fri Jan 05, 2007 1:57 pm
I am using the following controller action to output my users's images, and when a user changes their image, (avatar) it will take around a second to switch... meaning if you go to the image, it shows the old one for around a second and then it gets switched to the new one... is this a cache issue? What causes this?
Code: Select all
public function imageAction()
{
$request = $this->getRequest();
$get = new Zend_Filter_Input($request->getQuery());
$id = $get->getDigits('id');
// todo: move this into config table
$dir = 'C:\\htdocs\\ChicoRotary\\upload\\';
// Set photo defaults
$photoType = 'image/gif';
$photoPath = $dir . '\\unavailable.gif';
if ($id)
{
$user = new Model_User;
$user->loadId($id);
$photo = $user->photo;
}
if (!empty($photo))
{
$photoPath = $dir . $photo;
$image = new MC2_Image($photoPath);
$photoType = $image->getType();
}
$response = $this->getResponse();
$response->setHeader('Content-Type', $photoType);
$response->setBody(readfile($photoPath));
}