我使用content-type:image/jpeg创建了一个页面“student_picture.php”。有问题,当我想在同一页面中添加其他文本..如何正确使用content-type:image/jpeg?
IM这里是我的代码示例:
<?php
session_start();
if(!isset($_SESSION["StudentNo"])){
header("location:login.php");
}
$StudentNo = $_SESSION['StudentNo'];
require("includes/connection.php");
$sql = "SELECT StudentPicture from dbo.Students where StudentNo = '$StudentNo'";
$stmt = sqlsrv_query($conn, $sql);
if($stmt === false) {
die(print_r(sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {
$img = $row['StudentPicture'];
if ($img == null) {
echo "<img src='img/default_pic.gif'>";
} else {
$img = trim($img);
header('Content-Type: image/jpeg');
echo $img;
}
echo $StudentNo;
}
?>
的图像显示成功,但回声$ StudentNo没有显示..任何人都可以帮我解决我的问题吗?提前致谢。
请参阅相关的问题http://stackoverflow.com/questions/2428004/how-can-i-use-multiple-php-header-content-类型在同一页上,这是可能的 –