获取MySQL中二进制存取的图片,只能输出第一张,不能循环输出??
图片是以二进制的形式存入数据库的,不用while循环还能在浏览器上输出第一张,用了之后,输出的是乱码,是不是在输出图片之前不能有任何输出??
查了很多,都没有效果,求高手指点
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
<?php
require_once("conn.php");
$cover=$_POST['cover'];
if($_POST['sub']){
header("Content-Type:image/jpeg",true);
//以只读的方式打开二进制文件
$fp=fopen($cover,"rb");
$image=addslashes(fread($fp,filesize($cover)));
$sql1="insert into phototest (id,photo) values('','$image')";
$insert=mysql_query($sql1,$conn);
$sql2="select * from phototest";
$select=mysql_query($sql2,$conn);
//$result=mysql_fetch_array($select); echo $result[1];//用一条语句能输出一张图片
?> <table width="80%" height="80%" border="1"> <?php
while($result=mysql_fetch_array($select)){
//echo stripslashes($result['photo']); //stripslashes()去除反斜杠
?>
<tr height="400">
<td> <?php echo $result['photo']?> </td>
</tr>
<?php
}
?> </table> <?php
//关闭文件
fclose($fp);
?>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号