Webbie Webbie - 4 months ago 17
PHP Question

PHP Display all images from DB in a img tagg - PDO

Im trying to display alla images in a

<img>
from the db but i am only getting a broken image!
I am storing the ['tmp_name'] as LONGBLOB and the ['name'] as type in my tabel.

$query = $this->connection->prepare("SELECT * FROM images");
$query->execute();


$row = $query->fetchAll();

foreach($row as $img){
echo "<pre>";var_dump($img['name']);"</pre>";

echo "<img src=".$img["name"].">";
}

//header("Content-type: ".$row['type']);
print $row['name'];
die();


Should i use ['tmp_name'] or ['name'] in the
<img>
?

Answer

<img src=""> should include the full server path where your image is successfully uploaded. Also should include the image extension as well (.jpg, .png, .gif). should look like similar to following.

<img src="http://ichef.bbci.co.uk/images/ic/160xn/p0306tt8.png">

Easiest way is to check the source code of page and see if you get complete / correct path to the image. If not, check/change your code for missing part.

Comments