Welcome Guest, Not a member yet? Register   Sign In
Get uploaded picture from mysql database
#11

[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.
#12

[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.
#13

[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?
#14

[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?
#15

[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.
#16

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

[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'>";
#18

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB