![]() |
Problem when trying to display image from database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Problem when trying to display image from database (/showthread.php?tid=16552) Pages:
1
2
|
Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]FabD[/eluser] Hi, I can't display images stored into a database. After searching on the forum, i have found some idea and I did it. First the piece of code in the form/view file : Code: <img src="<?php echo base_url() ?>index.php/signal/marches/displayimage/<?php echo $marches['MA_ID'] ?>" border='0' align='left'/>; which gives me in the source file for an Id equal to 1 : Code: <img src="http://localhost/gerico/index.php/signal/marches/displayimage/1" border='0' align='left'/>; the function int the controller : Code: function displayimage(){ but no ID displayed via the 'echo' statement. and finally the function in the model : Code: function getImage($Id){ but again, nothing is displayed. So I guess the the call the controller's function doesn't work. But I don't see what is wrong. Can you help me ? Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]TheFuzzy0ne[/eluser] These functions might work a little better: Code: function displayimage($Id=FALSE) Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]FabD[/eluser] I applied the proposed code ... but still no image displayed. It seems that it doesn't reach the function displayimage() In the form/view, I have changed the call to the function displayimage() by a dummy call to an undefined function 'toto' : Code: <img src="<?php echo base_url() ?>index.php/signal/marches/toto/<?php echo $marches['MA_ID'] ?>" border='0' align='left'/>; Code: <img src="http://localhost/gerico/index.php/toto/1" border='0' align='left'/> and .... nothing happens, no errors reported. So it seems that CI ignores the call into the 'src' parameter of the image ... Any ideas ? where do I have to put the call to display the image ? Is my way of working wrong ? Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]TheFuzzy0ne[/eluser] It looks to me like your src attribute is not set correctly. What the name of your controller? The src attribute should look like this: Code: src="<?php echo site_url("controller_name/display_image/$image_id"); ?>" Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]FabD[/eluser] I have tried with site_url() insteod of using base_url() ... without success. The html source code seems right : Code: <img src="http://localhost/gerico/index.php/signal/marches/displayimage/1" border='1'/> The URL which call the page is Code: http://localhost/gerico/index.php/signal/marches/edit/1 the controller 'marches' is in the folder 'application/controllers/signal/'. Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]TheFuzzy0ne[/eluser] What happens when you put that address into your address bar? Have you checked the the database is actually returning an image, as I suspect it's not. Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]FabD[/eluser] when i put the url Code: http://localhost/gerico/index.php/signal/marches/displayimage/1 Code: A PHP Error was encountered As concerns the database (Oracle), I have put a jpeg image into the record with id 1 using PL-SQL Developer. Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]TheFuzzy0ne[/eluser] Your code is quite buggy. I'd recommend you go with what I proposed, and iron out any creases. The model passes back a string which is empty if no image is found. Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]FabD[/eluser] I think that the code that I ran is very closed to the one you proposed ;-) into the controller : Code: function displayimage($id=FALSE){ into the model : Code: function getImage($Id){ It doesn't display the first line of displayimage() : echo 'AAAAAAAAAAA' ; So, in my opinion, this method is never reached. Why ? that's the question ... Problem when trying to display image from database - El Forum - 03-10-2009 [eluser]TheFuzzy0ne[/eluser] I beg to differ. When you called on the URL directly, you got a PHP error related to that function. Fix that and you're one step closer to fixing the function. Work directly with the URL in the address bar until it does what you want it to do. |