I have a thumbnailing controller which seems to be working well, but
on a page with many thumbnails (around 60) occasionally one or two
thumbs get corrupted with the following PHP warning message at the top
of the binary image data:
Warning (2): unlink(/var/www/html/bsm/app/tmp/cache/persistent/
cake_core_object_map) [function.unlink]: No such file or directory
[CORE/cake/libs/file.php, line 276]
I can see it's something to do with caching but I'm not sure why it is
trying to delete this file.
It is a different image each time so I'm not sure how to debug this.
Here's the code for my thumbnailing controller, any help would be
greatly appreciated:
=====================
class ThumbsController extends AppController
{
var $name = 'Thumbs';
var $uses = null;
var $layout = null;
var $autoRender = false;
function beforeFilter() {
// since this controller is likely to get many requests in a
single
process,
// high security would cause the Auth Session to be dropped.
//$this->Session->security = 'medium'; // doesn't seem to work
Configure::write('Security.level', 'medium');
parent::beforefilter(); // call the parent so we don't
overwrite it
$this->Auth->allow('*'); // actions where no login is required
- set
this in each controller and call
}
function view()
{
// make sure we don't corrupt any images with debug info
Configure::write('debug', 0);
//pr($this->params['named']);
//exit;
if(empty($this->params['named']['src'])){
die("No source image");
}
$src =
str_replace('|',DS,$this->params['named']['src']);
// sanitize the src name a little
$src = str_replace('..','',$src); // remove any double
dots,
// this should probably do enough seeing as we're
tagging it onto
the end of the WWW_ROOT constant
// but just in case also filter out other mischievous
characters...
$src = preg_replace('/(^\/)|(^\.\/)|(~)/','',$src); //
remove any
starting / or ./
//width
$width = (!isset($this->params['named']['w'])) ? null :
$this->params['named']['w'];
//height
$height = (!isset($this->params['named']['h'])) ? null :
$this->params['named']['h'];
//quality - not implemented yet in imageserver
//$quality = (!isset($this->params['named']['q'])) ? 75 :
$this->params['named']['q'];
$sourceFilename = WWW_ROOT.$src;
$maxSrcPixels = 4000000; // images over around
3megapixels seem to
exhaust a memory limit of
if(!file_exists($sourceFilename) ||
!is_file($sourceFilename)) {
$sourceFilename =
WWW_ROOT.'img/admin/no-image.png';
}
$ext = strtolower(substr(strrchr($sourceFilename, '.'),
1)); // get
the file extension
if(!in_array($ext,array('jpg','jpeg','png','gif'))) {
$sourceFilename =
WWW_ROOT.'img/admin/image-unknown-format.png';
}
$imgsize = getimagesize($sourceFilename);
if(empty($imgsize)) {
die("Could not check size of source image with
getimagesize()");
}
if($imgsize[0] * $imgsize[1] > $maxSrcPixels) {
$sourceFilename =
WWW_ROOT.'img/admin/image-too-large.png';
}
if(is_readable($sourceFilename)){
vendor("imageserver/imageserver.class");
$i = new ImageServer;
$i->src = $sourceFilename;
$i->cache_path = CACHE.'thumbs'.DS;
$i->h = $height;
$i->w = $width;
$i->crop_anchor = 'C';
$i->cache_required = true;
if(!$i->output()) {
echo $i->error;
}
} else { // Can't read source
die("Couldn't read source image ".$sourceFilename);
}
}
}
=====================
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---