Welcome Guest, Not a member yet? Register   Sign In
Display a Image inside CodeIgniter
#1

[eluser]tank6b[/eluser]
Hi all,

I will like to show a image via this script

Code:
$im = file_get_contents('http://localhost/kyntana/assets/plain/images/badges/kyntana-logo-30px.png');
header('content-type: image/png');
echo $im;

But want to make it with a url like "site.com/i/myimage.png"

I think is a route problem but how can I do that?

Thanks in advanced!
#2

[eluser]louis w[/eluser]
Why don't you just do it all with mod_rewrite? Why are you going through CI to get to an image?
#3

[eluser]tank6b[/eluser]
[quote author="louis w" date="1204702865"]Why don't you just do it all with mod_rewrite? Why are you going through CI to get to an image?[/quote]

I will like to get the stats from how many time this image is displayed, that´s why i need to show it this way and get the info inside CodeIgniter, add it to the DB etc.
#4

[eluser]xwero[/eluser]
take a look at this
#5

[eluser]tank6b[/eluser]
[quote author="xwero" date="1204739948"]take a look at this[/quote]

That solve how to display the image but I need to load the image from a url like this "site.com/i/myimage.png" and this url will call a controller inside CI.
#6

[eluser]louis w[/eluser]
Check out the routes function. This lets you use a short path like that and route it to a specific controller. Something like this might work:

Code:
$route['i/(:any)'] = "images/load/$1";
Where 'images' is your controller name, and 'load' is the method.
#7

[eluser]xwero[/eluser]
Why do you need to load it form a url if you regenerate the image using php?
Code:
// helper code
function image($path)
{
   include('image.php?path='.$path);
}
// controller code
function selectedimage()
{
   $file = $this->model->get_file_and_up_counter($this->uri->segement(3));
   // load helper with function or load it in the contruct
   image($this->config->base_url().'kyntana/assets/plain/images/badges/'.$file);
}
#8

[eluser]louis w[/eluser]
You can not set variables in the path of an include (?path=$path). In this case it will access $path from the same level as the include, but if you did something like ?path=$thepath then $path in image.php would not be valid.
#9

[eluser]tank6b[/eluser]
[quote author="louis w" date="1204742765"]Check out the routes function. This lets you use a short path like that and route it to a specific controller. Something like this might work:

Code:
$route['i/(:any)'] = "images/load/$1";
Where 'images' is your controller name, and 'load' is the method.[/quote]

I'll try that and let you know if work.

The image badges will be hot linked from external sites that's why I need to keep the url as a normal image on the browser.
#10

[eluser]tank6b[/eluser]
The route thing work like a charm!

Thanks you all! CodeIgniter Comunity is by far the best Development Comunity ever!




Theme © iAndrew 2016 - Forum software by © MyBB