如何在php/mysql中显示数据库中的图像。如果使用C/Vb.net将图像插入数据库中
我有两个应用程序,一个是桌面应用程序,另一个是web应用程序 我们使用桌面应用程序将图像存储在数据库中,在mysql中使用c.net/mysql blob数据类型,因为图像是由签名设备捕获的 我想在web应用程序中显示该图像,但它不起作用。我正在使用如何在php/mysql中显示数据库中的图像。如果使用C/Vb.net将图像插入数据库中,php,mysql,Php,Mysql,我有两个应用程序,一个是桌面应用程序,另一个是web应用程序 我们使用桌面应用程序将图像存储在数据库中,在mysql中使用c.net/mysql blob数据类型,因为图像是由签名设备捕获的 我想在web应用程序中显示该图像,但它不起作用。我正在使用 $im = imagecreatefromstring($data); if ($im !== false) { header('Content-Type: image/png'); imagepng($im);
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
}
else {
echo 'An error occurred.';
}
警告:imagecreatefromstring:中的数据格式不可识别
这就是我在DB中保存数据的方式@
Dim myimage As Image
Dim fileName As String = "c:\img.jpg"
myimage.Save(fileName, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imgBytes() As Byte = Nothing
Dim uFileInfo As New IO.FileInfo(fileName)
Dim uFileLength As Long = uFileInfo.Length
Dim uFstream As New FileStream(fileName, FileMode.Open, FileAccess.Read)
Dim uBinaryReader As New BinaryReader(uFstream)
imgBytes = uBinaryReader.ReadBytes(Convert.ToInt32(uFileLength))
Dim Cmd As New System.Data.Odbc.OdbcCommand("update tbl set Sign=? where ID='1', ConnectionString)
Dim param1 As System.Data.Odbc.OdbcParameter
param1 = New OdbcParameter("?", OdbcType.Binary)
param1.DbType = DbType.Binary
param1.Value = imgBytes
param1.Size = imgBytes.Length
Cmd.Parameters.Add(param1)
这是数据库中的数据
ÿØÿa JFIFÿC
$。,701444'9=82首先,从桌面应用程序中的某个位置上载图像,只将文件位置保存到数据库中可能会更明智 如果你真的想坚持当前的实现,你应该制作一个php文件来显示图像,例如image.php
// database connection here
// get data from database where id = x
echo '<img src="data:image/jpeg;base64,' . base64_encode($data) . '"/>'
像这样使用它
echo '<img src="image.php?id=x"/>'
可能重复的请显示您如何保存图像的代码。@ChrFin保存代码为posted@AtifMajeed这应该可以做到。你能编辑你的问题并添加你用来在数据库中插入图像的代码吗?@AtifMajeed我的vb很差,但与我发现的其他示例相比,它看起来很好。我想,你能试试我做的编辑吗?
echo '<img src="image.php?id=x"/>'