CodeIgniter Forums
Get uploaded picture from mysql 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: Get uploaded picture from mysql database (/showthread.php?tid=55148)

Pages: 1 2


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
How important is to set up the htaccess? Since i started using CI. I didn't set set up the htaccess. Bty the way thanks for the effort i will try another way. Thanks.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]LuckyFella73[/eluser]
You don't have to set up a htaccess file. I just guessed you did
because you often get simular error messages is you messed something
up there.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
Hello i made an error a while ago when i run this code it shows the path
Code:
$this->load->library->('database');
$this->db->select('file_path');
$query = $this->db->get('upload');

if ($query->num_rows() > 0)
{
$row = $query->row();
$path = $row->file_path;
}
echo "Path from DB: ".$path;
exit();

Output
Code:
Path from DB: http://localhost/eMLM/upload/Winter.jpg

But when i run the image tag it shows an image border with an icon in the middle. Does it means my path is incorrect?


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]LuckyFella73[/eluser]
You said that if you build your image HTML tag manually
Code:
<img src='http://localhost/eMLM/upload/Sunset.jpg' height='100' width='100'>

The image is displayed. And your test code is echoing the right path.
So it seems that something went wrong when passing the path from model/
controller to your view.

Can you post all relevant code you have for this task? Contoller/model
and view?


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
Controller:

Code:
public function viewMember(){
            $data['user'] = $this->user_model->getUserWhere();
            $this->load->view('sites/viewmember',$data);
            $this->load->view('templates/footer');
}

View
Code:
&lt;?php
              
                    $this->db->select('file_path');
                    $query = $this->db->get('upload');

                    if ($query->num_rows() > 0){
                        $row = $query->row();
                        $path = $row->file_path;
                    }
                    echo "Path from DB: ".$path;
                    echo "<img src='$path' height='100' width='100' alt='from database'>";  //displays image border only
                    exit();
              ?&gt;

By the way i didn't use a model this time. I redirect my query to the view.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
My controller does not do anything with the image it only calls my view


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]LuckyFella73[/eluser]
Please try:
Code:
echo '<img src="'.$path.'" height="100" width="100" alt="from database">"';

// instead of:
echo "<img src='$path' height='100' width='100' alt='from database'>";



Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]rochellecanale[/eluser]
It display the same.


Get uploaded picture from mysql database - El Forum - 10-15-2012

[eluser]CroNiX[/eluser]
I would only store the image name in the db. If you store the whole url including host name and dir paths, if you ever change servers (or dir structure) you have a lot of work to do since everything in the db would now be wrong. If you only store the filename, then nothing changes except you update one thing (the path), and you would just use site_url() for generating hostname portion.

For instance, you have everything hardcoded in the db for "localhost" server. What happens when you put this on a real server? None of that will work any longer.