我正在尝试显示已上传到mysql数据库的图像。当我尝试检索图像时,它只显示文件名而不是实际图像本身。下面是上传图片的代码,我不确定我是否已正确完成或包含图像的任何相关路径。我将如何显示数据库中的图像?
<form method = "post" action ="" enctype="multipart/form-data" >
<input name="userfile" type="file" id="userfile">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="submit" value="Upload Image" name="submit">
</form>
<?php
$filename = $_FILES['userfile']['name'];
$tmpname = $_FILES['userfile']['tmp_name'];
$filesize = $_FILES['userfile']['size'];
$filetype = $_FILES['userfile']['type'];
$fp = fopen($tmpname, 'r');
$content = fread($fp, filesize($tmpname));
$content = addslashes($content);
fclose($fp);
$query = "INSERT INTO `table` (`ID`,`name`,`type`,`size`,`content`)
VALUES( NULL,'$filename', '$filetype', '$filesize', '$content')";
if($mysqli->query($query)){
echo '<h3>Offer posted</h3>';
} else {
echo "error";
}
?>