【发布时间】:2014-10-10 10:46:44
【问题描述】:
在图片库的情况下,图片包含标题、描述和其他信息。
我想在响应中传输所有信息(连同图像数据)。这可能吗,在单个 HTTP 响应中。
我问的原因是,在数据库中,在单个查询中,所有内容都可以返回,即。图片路径、它的标题、描述等。所以,在一个响应中返回所有内容会不会有好处。
目前,我能够从数据库中获取图像路径和名称(写为图像路径)并将图像返回给用户。
我的(通常获取、读取和输出文件)后端代码 (Php):
$img_id=$_GET['id'];
$con=mysqli_connect('localhost','username','password','mydb');
$stmt= mysqli_prepare($con,'select imagepath,description,title from images where imgid=?');
mysqli_stmt_bind_param($stmt,'s',$img_id)
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $imgpath,$desc,$title);
if (!mysqli_stmt_fetch($stmt)) return ;
//single result
if (file_exists($imgpath))
{
header('Content-Type: image/png');
header('Content-Length: ' . filesize($imgpath));
readfile($file);
}
// 目前,我无法通过此发送 desc 和 title。有没有办法在单个响应中发送它们? 另外,有没有办法在浏览器端使用 javascript 来检索它们?
【问题讨论】:
-
您的问题需要更加具体。发布相关代码,显示您所做的尝试。就目前而言,您的问题太宽泛,无法回答
标签: html image http web metadata