[英]Image from getImage.php won't display in img src
So basically if I go to the getImage
link, the image that comes from the database is displayed, but if I use it in a .php
file where it will display the image but will resize it to fit the card, it won't show and the alt (which is avatar) shows.所以基本上,如果我转到
getImage
链接,就会显示来自数据库的图像,但是如果我在.php
文件中使用它,它将显示图像但会调整其大小以适合卡,它不会显示和 alt(这是头像)显示。
<center>
<img src="getImage.php" class="w3-circle" style="position:absolute; bottom:-20%; left:35.5%; width:30%" alt="Avatar">
</center>
Then the code for the getImage.php
:然后是
getImage.php
的代码:
<?php
session_start();
require './Database.php';
// do some validation here to ensure id is safe
$sql = "SELECT register.FULLNAME, register.IMAGE, gameData.NBA_SCORE FROM register inner join gameData on register.ID = gameData.ID WHERE NBA_SCORE = (select max(NEW_SCORE) from gameData)";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($result);
echo "<img src='".$row['IMAGE']."'>";
?>
Anything wrong with what I am doing?我在做什么有什么问题吗?
Problem问题
HTML trys to get an valid image file like jpg or png but gets an php/text file with the content <img src="...">
. HTML 尝试获取有效的图像文件,如 jpg 或 png,但获取内容为
<img src="...">
的 php/text 文件。
Solution解决方案
You need to change the php files content type to an image and output the image files data:您需要将 php 文件内容类型更改为图像并输出图像文件数据:
header("Content-Type: image/jpeg");//or image/png
echo file_get_contents("$imagepath");//file path not url!!!
Code代码
<?php
session_start();
require './Database.php';
header("Content-Type: image/jpeg");
// do some validation here to ensure id is safe
$sql = "SELECT register.FULLNAME, register.IMAGE, gameData.NBA_SCORE FROM register inner join gameData on register.ID = gameData.ID WHERE NBA_SCORE = (select max(NEW_SCORE) from gameData)";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_assoc($result);
$path = $row['IMAGE'];//Maybe you need to change this if you only save an url in the database
echo file_get_contents($path);
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.