[英]Display an image in php from database
大家好,我试图在数据库中以php显示图像,我将图像的名称添加到数据库中,而不是扩展名,我现在想检索此名称并将其扩展名放在表中,并将其显示在表单上但我有一些困难,它根本没有用,有人可以帮忙吗
$id = null;
$Cover= null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: index.php");
} else {
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
$q = mysqli_query($dbc,"SELECT * FROM movie WHERE MovieID = '$id' ");
while($r=mysqli_fetch_array($q))
{
$title = $r["Title"];
$tag = $r["Tag"];
$Year = $r["YEAR"];
$Cast = $r["Cast"];
$Cover = $r["Cover"];
}
以下是提取代码
$name = FALSE; // Flag variable:
// Check for an image name in the URL:
if (isset($_GET['image'])) {
// Make sure it has an image's extension:
$ext = strtolower ( substr ($_GET['image'], -4));
if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) {
// Full image path:
$image = "uploads/{$_GET['image']}";
// Check that the image exists and is a file:
if (file_exists ($image) && (is_file($image))) {
// Set the name as this image:
$name = $_GET['image'];
} // End of file_exists() IF.
} // End of $ext IF.
} // End of isset($_GET['image']) IF.
// If there was a problem, use the default image:
// Get the image information:
$info = getimagesize($image);
$fs = filesize($image);
// Send the content information:
header ("Content-Type: {$info['mime']}\n");
header ("Content-Disposition: inline; filename=\"$name\"\n");
header ("Content-Length: $fs\n");
// Send the file:
readfile ($image);
}
?>
$ image未按您的评论定义。
$ext = strtolower(substr($_GET['image'], -4));
var_dump($ext, $_GET['image']);
if (($ext == '.jpg') OR ($ext == 'jpeg') OR ($ext == '.png')) {
// Full image path:
$image = "uploads/{$_GET['image']}";
// Check that the image exists and is a file:
if (file_exists($image) && (is_file($image))) {
// Set the name as this image:
$name = $_GET['image'];
$info = getimagesize($image);
$fs = filesize($image);
// Send the content information:
header("Content-Type: {$info['mime']}\n");
header("Content-Disposition: inline; filename=\"$name\"\n");
header("Content-Length: $fs\n");
// Send the file:
readfile($image);
} // End of file_exists() IF.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.