我在mysql上已经保存了图片的路径,使用getdata.php输出图片,具体代码是这样<?php
$id = $_GET['id'];
$dbms='mysql';
$host='localhost';
$dbname='USER';
$user='928037604';
$pass='523150';
$dsn="mysql:host=$host;dbname=$dbname";
$pdo=new PDO($dsn,$user,$pass);
$query = "select filename,path from myuser where id=$id";
$result=$pdo->query($query);
if($result){
$result = $result->fetchAll(2);
echo "<img src=".$result[0]['path']." width=200px height=200px border=0>";
}
else{
echo "Handle errors";
}
?>
然后在另一个user.php用<img src="getdata.php?id=xxx">为什么显示不出来图片,可是直接打开getdata.php在浏览器传值是可以打开图片的,求大神解答这是怎么回事
$id = $_GET['id'];
$dbms='mysql';
$host='localhost';
$dbname='USER';
$user='928037604';
$pass='523150';
$dsn="mysql:host=$host;dbname=$dbname";
$pdo=new PDO($dsn,$user,$pass);
$query = "select filename,path from myuser where id=$id";
$result=$pdo->query($query);
if($result){
$result = $result->fetchAll(2);
echo "<img src=".$result[0]['path']." width=200px height=200px border=0>";
}
else{
echo "Handle errors";
}
?>
然后在另一个user.php用<img src="getdata.php?id=xxx">为什么显示不出来图片,可是直接打开getdata.php在浏览器传值是可以打开图片的,求大神解答这是怎么回事
用于展示图片的php文件, 需要获取到图片, 然后直接展示出来, 这样才可以供img 直接调用:
php 直接展示打印图片:
header('Cache-Control: private, max-age=0, no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header("content-type: image/png"); // 输出图像
imagepng(self::$_image);
imagedestroy(self::$_image);
echo "<img src=".$result[0]['path']." width=200px height=200px border=0>"; // 这里不加 <img /> 标签, 才对吧?
echo $result[0]['path'];