使用变量作为图片网址

时间:2013-10-15 17:58:03

标签: php

我有这张图片www.site.com/folder1/image1.jpg,我想要做的是从变量访问我的图片,例如www.site.com/image.php?q=varForImage1,它需要使用<img>标记。
例如:
<img scr="www.site.com/image.php?q=varForImage1">

任何帮助?

由于

2 个答案:

答案 0 :(得分:0)

<?php
// define $image_path as required
$image_path;
header('Content-type:'.mime_content_type($image_path));
echo file_get_contents($image_path);
die();

答案 1 :(得分:0)

这样的事情:

<?php
$image = $_GET['q'];  
$file = fopen('/path/to/'.$image, 'rb');  
header("Content-Type: image/png");

嗯,你当然应该改进代码,它可能只是给你一个想法。