Hello,
I’m having some problem displaying images… it’s for a portfolio website, the user can upload images, they’re stored on the filesystem and the path is stored in the database.
I have a PortfolioImage model, a ThumbImage model, and the portfolioController with this action (added some logging…) :
/**
* Displays the thumb of an image
* @param integer $id the ID of the image from which the thumb should be displayed.
*/
public function actionThumb($id)
{
$model=$this->loadImage($id);
if($model->thumb){
if(!is_file($model->thumb->filepath)) {
error_log('not found');
}
if(!is_readable($model->thumb->filepath)) {
error_log('not readable');
}
error_log('ok, reading thumb '.$model->thumb->filepath);
header("Content-Type: ". $model->thumb->mime);
header("Content-Length: " . $model->thumb->filesize);
//ob_clean();
//flush();
echo file_get_contents($model->thumb->filepath);
exit;
} else {
// return full size image
$this->redirect(array('portfolio/image', 'id'=>$id));
}
}
And I display all the images in the portfolio in my view as follow :
<?php echo CHtml::image(Yii::app()->createUrl('portfolio/thumb', array('id'=>$data->id)), null, array('width'=>$data->thumb->width, 'height'=>$data->thumb->height) ); ?>
Basically it tries to load the thumb of the image, if not found it loads the main image. It works, I can see the image thumb, there’s no problem with the model/controller. But as soon as I reach 8 images, I experience some strange problems…
I currently have 11 images. The first 8 images are correctly loaded and displayed. Then it hangs for a couple of seconds and I can see in the log that the last 3 images are loaded. But some of them don’t show in the browser (not always the same). For these failing images I can see in Chrome developer tools that I’m getting a response header HTTP 0.9/200 OK. But it’s empty.
I’ve tried different method to read and display the images (readfile, file_get_contents, fopen/fpassthru, I always get the same problem. And it’s not always the same images… but I never get all the images to display correctly, whatever I do (I get between 6 and 8 images ok, not always the same…).
I can’t see any error in apache nor php logs… here are the php error_log with the trace, you can see the 5 seconds gap after the first 8 images :
25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/525cf1538e01a_IMG_7381.JPG
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/525cf1b89405d_IMG_1082.JPG
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/525cf1567e818_IMGP1042.JPG
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/525cf15532931_IMGP0809.JPG
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/525439bca4f0d_mercator-bw.png
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/5252d08d6cbcc_memorialmem_no_trees.jpg
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/524ed6a2126cc_DSC01374.JPG
[25-Oct-2013 10:35:45 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/524ed69c87327_DSC02912.JPG
[25-Oct-2013 10:35:50 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/524ed6a80ae8e_DSC01579.JPG
[25-Oct-2013 10:35:50 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/524ed6a4bec0b_DSC01876.JPG
[25-Oct-2013 10:35:50 Europe/Berlin] ok, reading thumb /Users/fab/code/architectural-render-app/web/protected/config/../../uploads/19/portfolio/thumbs/524ed6a3b0341_DSC02481.JPG
I’m basically out of ideas… can it be some cache issue ? same issue happens in firefox, and I also tried on a different host, same thing. If I replace the controller action call by the hard coded urls in the view, it works fine… but I’d rather not do that.
Any idea ?
Thanks !