虚拟img src到真实路径


virtual img src to real path

我为数据库表中的每个图像分配了一个ID,这些图像也有到图像的真实路径,包括像这样的真实名称

Table images {
id = '23432.jpg',
path = 'foo/bar',
name = 'baz.jpg' }

是否可以保留img src="2343.jpg",并在不使用"data:image.jpg;base64'只是表id[223432.jpg]?

或者这是一个.htaccess作品!

<img src="/images/1234.jpg">

RewriteEngine On
RewriteRule ^images/(.*)$ script.php?$1 [L]

将所有到子目录images的请求重定向到script.php,并放入query_string请求的文件名中。您只需要在脚本中获取它,在DB中找到相应的图像,从磁盘中读取它,并输出正确的content-type标头。如果图像不在数据库中,则输出404错误。

这里假设路径变量有图像的路径,名称是图像文件的名称。

所以,您必须首先给出mysql查询,才能从表中获取路径和图像名称。

$q1="select path,name from images where id=".$id;
$rs=mysql_query($q1);

 while($r=mysql_fetch_array($rs))
 {
      $path=$r[0];
      $imgname=$r[1];
      $completeimgpath=$path."/".$imgname;
      echo "<img src=".$completeimgpath." width=300 height=300 />"
   }