php mysql 图像,从mysql php获取图像

博主在尝试将员工头像上传到MySQL数据库并检索时遇到问题。图片能成功存储,但在检索时显示不正常,呈现出类似文本编辑器中乱码的效果。目前的PHP代码分别用于上传和检索图片。问题在于如何正确检索图片,并询问是否存在其他存储图片到MySQL的替代方案,比如将图片保存到文件系统并存储链接到数据库。
摘要由CSDN通过智能技术生成

here i am trying to upload the employee profile picture to mysql and then i want to fetch those picture. now i can uploaded the image into mysql db successfully but, when i try to fetch the image that doesn't fetch properly. if you open an image in texteditor na how it will look like? the same thing i got it now.. like this... (QÕf0±Ó%"÷YúEûVÚo¾e9°R}È"!5®?•Ÿ\¯ž›ÃÕîYU0T³¼´œ\aVë%z€ÙBðŒÆnPÈ Qx•eú0´ÁPÁ”·=ó-)Oyá+×½ÄS„ÞšÅS!Y¨;,¾¤ª5HÅÓôÍó3Áº¶j/"5±•RX›ee.&{ +C˜ H CÌai,F+Ô#”?Ì8««IÐO%IW).

my question is how to fetch the image properly? and then is there any other way to do store an image to mysql db. for example save a employee profile pictures to one folder and then store that link to mysql???

index.php code:

include("config.php");

$query = mysql_query("SELECT * FROM tbl_images");

while($row = mysql_fetch_array($query))

{

echo "" . $row['image'] . "";

}

?>

img.php code:

include("config.php");

if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {

$tmpName = $_FILES['image']['tmp_name'];

$fp = fopen($tmpName, 'r');

$data = fread($fp, filesize($tmpName));

$data = addslashes($data);

fclose($fp);

$query = "INSERT INTO tbl_images ";

$query .= "(image) VALUES ('$data')";

$results = mysql_query($query, $link) or die(mysql_error());

print "Thank you, your file has been uploaded.";

}

else {

print "No image selected/uploaded";

}

?>

解决方案

Can you try this,

echo '';

Your code:

while($row = mysql_fetch_array($query))

{

echo '';

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值