大家好我试图在我的数据库中显示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);
}
?>
答案 0 :(得分:0)
$ 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.
}