Jump to content

CodeIgniter Image Loader


ShoeLace1291

Recommended Posts

I'm trying to extend the codeigniter loader class with a function that outputs an image based on content provided through a parameter.  When I try to view the file, i get the following error:

 

The image “http://localhost/lensereflex/main.php/images/test” cannot be displayed because it contains errors.

 

This is my loader class:

<?php

class MY_Loader extends CI_Loader {

function dynamic_image($content = '', $type = 'jpeg', $file_name = FALSE){

	if($content == ''){
		show_error('There is no output to display.');
		return FALSE;
	} else {
		header('Content-Length: '.strlen($content));
		header('Content-Type: image/'.$type);
		if($file_name == TRUE){
			header('Content-Disposition: inline; filename="'.basename($file_name).'";');
		}
		return $content;
	}

}

}

 

This is how I call the function:

 

<?php
class Images extends CI_Controller {

     function test(){

          $this->load->dynamic_image('Image Test', 'jpeg', 'test.jpg');

     }

}

 

Link to comment
https://forums.phpfreaks.com/topic/238617-codeigniter-image-loader/
Share on other sites

did you reconfigure your routes.php in the config folder in the routes php to support "main.php" instead of "index.php"?

 

Also what your attempting to do may better be served as a module that you load into a controller.. instead of the extension concept.

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.