Photo Gallery using Picora
The source code (precedent post doesn't display it) :
class ImageController extends ApplicationController
{
public function thumb($format, $image)
{
list($w, $h, $mode) = explode('_', $format);
$cache = IMAGE_CACHE.$format.'_'.$image;
$image = IMAGE_DIR.$image;
$imageInfo = getimagesize($image);
if (!file_exists($cache))
{
//
// Thumbnail generation
//
}
header('Content-type: ' . $imageInfo['mime']);
header('Expires: ' . date(DATE_RFC822, time()+24*3600));
header('Cache-Control: max-age=3600');
readfile($cache);
}
}
Posted May 24th, 2007 at 4:39pm by SuperDevy
I believe Only Picora can send headers to the browser (it happens when it's done with the controller and a view is being rendered), if more than one statement try to do that in the same flow you'll get this error. Maybe you can hijack this behaviour by using beforeDisplay() and send headers there and die()
(just a guess)
Posted May 25th, 2007 at 9:04am by nolan
It's actually not a header problem, it's an output problem. You can issue headers anywhere, and you can also issue the same one's multiple times. But you can't issue them if output has been sent. "Output has been sent" could be any of the following:
- Any whitespace outside of the PHP tags (beginning and end of the file) count as output
- Any output sent with "print" or "echo"
But as the error says, output started on line 84 in ImageController.php, so something is sending output at that line, after which you can't send any more headers.
Posted May 25th, 2007 at 9:35am by ryan
Thanks for your answers.
The use of die or exit function solves my problem, but that is not really a good method.
I have found that output was sent ApplicationController::render (Sample Blog) But my controller doesn't return anything.
I have simply change my ImageController class to extends directly PicoraController and not my ApplicationController.
class ImageController extends PicoraController
{
public function thumb($format, $image)
{
// The same
}
}
Now all is OK.
Posted May 25th, 2007 at 1:43pm by SuperDevy
My bad, I meant 'output' of course.
Posted June 22nd, 2007 at 7:08am by nolan
Hello,
I'm currently developing a photo gallery using Picora. Developement of html pages structure is very easy with this micro framework, it's a great tool.
But I want ti generate images with a controller function. Every thing is right with graphic library, but I have a problem due to Picora. After sending a HTTP header and image content in controller I get an error at the end of the image :
My Controller is :
How should I do ?
PS: Escuse my poor english.
Posted May 24th, 2007 at 4:37pm by SuperDevy