显示图像时出现错误ERR_EMPTY_RESPONSE

时间:2018-11-19 02:36:24

标签: php mysql

我有这段代码已经工作了几个月没有任何问题。现在此页面无法正常工作,并且是php代码中的问题,但我不知道

在哪里

	<?php


 $query = "SELECT * FROM offerimage order by name";

$result = mysqli_query($connection, $query);

if ($result->num_rows > 0) {
    
	echo "<table>";

    while($row = $result->fetch_assoc()) {

       echo "<tr>";
 
 
  $image = '<img src="data:image/jpeg;base64,'.base64_encode($row['image'] ).'" height="100" width="100"/>';
 
 
//echo '<br></br>';	
echo $image;
echo '<br></br>'; 
	   echo "</tr>";
		
    }
} else {

	echo "</table>";
}

?>

我收到此错误

“ ERR_EMPTY_RESPONSE”

this is page of the error

2 个答案:

答案 0 :(得分:0)

为什么查询不返回任何行时不输出某些内容,因为这可能是原因?

此外,您还应该将图像包含在<?php header('Content-type : bitmap; charset=utf-8'); if(isset($_POST["encoded_string"])){ $encoded_string = $_POST["encoded_string"]; $image_name = $_POST["image_name"]; $decoded_string = base64_decode($encoded_string); $path = 'images/'.$image_name; $file = fopen($path, 'wb'); $is_written = fwrite($file, $decoded_string); fclose($file); if($is_written > 0){ $connection = new mysqli('localhost','id7794597_razzlesz','hahayz9090','id7794597_memes'); $query = "INSERT INTO photos (name,path) values ('$image_name','$path');"; $result = mysqli_query($connection, $query); if($result){ echo "success"; }else{ echo "failed"; } mysqli_close($connection); } } 元素中。

经过编辑以显示图像的逐行检索。假设数据库表<td>具有一个名为offerimage的唯一整数ID(例如AUTO_INCREMENT列),请更改查询以匹配实际的表定义。

id

其他建议:如果只需要一列,请不要使用<?php // get array of offerimage IDs ordered by name $query = "SELECT id FROM offerimage order by name"; $result = mysqli_query($connection, $query); $ids = []; while ($row = $result->fetch_assoc()) { $ids[] = (int)$row['id']; } if (count($ids) > 0) { // display each image echo '<table>'; foreach ($ids as $id) { $query = "SELECT image FROM offerimage WHERE id = {$id}"; $result = mysqli_query($connection, $query); $row = $result->fetch_assoc(); echo "<tr><td>"; echo '<img src="data:image/jpeg;base64,'.base64_encode($row['image'] ).'" height="100" width="100"/>'; echo "</td></tr>"; mysqli_free_result($result); } echo "</table>"; } else { echo "<p>No offers found.</p>"; } 。请改用SELECT *

在建立数据库连接时检查错误(不显示代码),并从查询中使用SELECT image或发送到浏览器,以便查看那里是否出了问题。

答案 1 :(得分:0)

我通过将图像保存在文件夹中,然后将图像位置保存在DB中来解决此问题。