Welcome Guest, Not a member yet? Register   Sign In
Call Image Path From Database
#1

[eluser]rochellecanale[/eluser]
hello guys. How can i call the image from my upload folder?

Here's my path in upload folder.
Code:
C:\xampp\htdocs\eMLM\uploads

Here's the path with image
Code:
C:\xampp\htdocs\eMLM\uploads\Sunset.jpg

I putted the path in the database like this
Code:
http://localhost/eMLM/upload/Sunset.jpg
using the file_path

But it does not shows any image. It shows an image icon and a border the icon looks like a tear paper. How can i call the image from my folder? Please help me guys.

I try to pull out the info from my database like this:

Code:
$this->db->select('file_path');
$query = $this->db->get_where('upload',array('username'=>'andromeda009'));
$row = $query->row();
$path = $row->file_path;

echo "<img src='{$path}' width='100' height='100' />";

But nothing shows.
#2

[eluser]surf66[/eluser]
Hi, on my application I just save the image name to the db and I show the image in my view like this:

Code:
<img src="&lt;?php echo base_url('uploads/' . $image_thumb); ?&gt;" />

Also when your echoing the var $path I don't think you should have the curly braces there if it was me I would try this:

Code:
<img src="&lt;?php echo $path; ?&gt;" alt="Your alt text" />

I hope this can help in any way
#3

[eluser]CroNiX[/eluser]
What does your html look like for that img tag once the page is rendered? When you see the image missing icon, do a view source and post the HTML for that img. Whatever path is there for the src should give you an indication of what's going wrong.

Also, if you go to:
http://localhost/eMLM/upload/Sunset.jpg

Do you see your image?
#4

[eluser]rochellecanale[/eluser]
No it displays page not found. So i can't call the image directly? Hmm.. Ok thanks. I will do your advice. Hope it works.
#5

[eluser]rochellecanale[/eluser]
Ok thanks
What i did is replace the code with this

Code:
<img src="&lt;?php echo base_url('uploads/' . $image_thumb); ?&gt;" />

Thanks again.
#6

[eluser]boltsabre[/eluser]
To save a little time coding, I created a few site wide variables, ($IMG_PATH, $CSS_PATH, and $JS_PATH), in my MY_Controller (but you could do it in your config file or whatever suits you best).

Then you can just do this:
Code:
<img src="&lt;?php echo $IMG_PATH.$image_thumb); ?&gt;" />

It has the advantages that if you every change your directory structure (ie, you move your images from "uploads" to a new folder called "public/images") all you have to do is change $IMG_PATH and everything else will still work! With your current set-up, if you ever change your directory structure you will have to go and change EVERY image src="..."




Theme © iAndrew 2016 - Forum software by © MyBB