如何使用php从数据库(基于用户id)获取图像url并将其显示为图像。http://mysite.com/img.php?id=338576
下面的代码显示一个php脚本进入数据库,检查特定用户(使用上面链接中的id )是否存在,然后从该用户的行中获取图像url。
<?php
//connect to database
include ("connect.php");
//Get the values
$id = mysql_real_escape_string($_GET['id']);
//get the image url
$result = mysql_query("SELECT * FROM users WHERE id='$id'")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$img_url = row['imgurl'];
mysql_close($connect);
}
else{
}
?>$Img_url是一个实际的图像链接: www.asite.com/image.jpg
问题是如何使用php从图像链接($img_url)生成图像?通过它,http://mysite.com/img.php?id=338576将变成一个图像。
我希望有人能引导我
谢谢!
发布于 2011-12-05 04:54:13
最简单的方法:
header('Location: url/to/image');您还可以代理请求,它使用您的带宽:
echo(file_get_contents('url/to/image'));发布于 2011-12-05 04:54:51
这是相当基本的东西。我对你的理解正确吗?我只想这么做:
<?php
$img_html = '<img src="' . $img_url . '" />';
echo $img_html;
?>或者检查这个答案:How do I script a php file to display an image like ?
https://stackoverflow.com/questions/8381144
复制相似问题