2011-08-20 33 views
0

我正在编写一个CMS,用户可以发布一些新闻和评论。我有图像问题。想要将所有帖子的所有图像放在一个文件夹中,并通过帖子ID和图像ID访问它们(每个帖子从0开始)如何在PHP脚本中放置图像链接

我无法做到的唯一事情就是在脚本中生成图像链接。我在网上看到一些页面做同样的事情。像这样:

<img src=https://www.somewhere.com/uploads/image.php?postid=20&id=80> 

编辑:澄清,假定存在http://www.somewhere.com/uploads/1_2.jpg图像如何脚本可以通过图像时https://www.somewhere.com/uploads/image.php?postid=x&id=y在某处img标签的来源是什么?

+0

你可以把图像位置从数据库与“=帖子ID 20&ID = 80”,那么在src中回显它。这很简单。 – mithunsatheesh

+0

那么在HTML页面的源代码中真实位置会显示正确吗?我不会将它显示在页面上。 –

+0

okk ..知道了... – mithunsatheesh

回答

1

使用$ _GET ['postid']和$ _GET ['id'],您可以读取请求的postid和id作为images.php中的变量,然后返回标题和原始图像数据。只是一个简单的例子,你可以探索:

<?php 

$postid = $_GET['postid']; 
$id = $_GET['id']; 

header("Pragma: public"); 
header("Content-Type: image/jpg"); 
header("/var/www/img/".$postid."_".$id.".jpg"); 
readfile('/var/www/img/'.$postid.'_'.$id.'.jpg'); 

?> 

我希望这会帮助你。

编辑:您可以使用和帖子ID号从数据库中获取图像的位置等

+0

谢谢。这正是我一直在寻找的:) –