2013-03-08 108 views
-1

我想做的事情在PHP加载图片

以下

我有一个目录中的图片,我需要使用装载在一个PHP文件干净的页面的图片"site.com/image.php?pic=xx/xx.jpg"

例子:http://freeminecraftaccount.org/image.php?pic=images/minecraft.jpg

if (file_exists('image.html')) { 
    $temfile = fopen('image.html', 'r'); 
    $template = fread($temfile, filesize('image.html')); 
    if ($title) { 
     $template = eregi_replace("<PICTURETITLE>", $title, $template); 
    } else { 
     $template = eregi_replace("<PICTURETITLE>", $notitle, $template); 
    } 
    if ($desc) { 
     $template = eregi_replace("<PICTUREDESCRIPTION>", $desc, $template); 
    } 
    if ($pic) { 
     $template = eregi_replace("<PICTURE>", "src=\"$pic\">", $template); 
    } else { 
     $template = eregi_replace("<PICTURE>", $noimage, $template); 
    } 
    if ($return) { 
     $template = eregi_replace("<PICTURELINK>", "<a href=\"$return\">RETURN</a>", $template); 
    } else { 
     $template = eregi_replace("<PICTURELINK>", "<a href=\"/\">RETURN</a>", $template); 
    } 
    echo $template; 
} 

?> 

如果有人能帮到,那太好了 谢谢!

+0

[你尝试过什么(http://www.whathaveyoutried.com )?你还需要更多的细节。有许多方法可以使用'$ _GET'在PHP中加载图像 – UnholyRanger 2013-03-08 19:07:45

回答

0
<?php 
    if (isset($_GET['pic'])){ 
     $pic_location = $_GET['pic']; 
    } 
    else { 
     $pic_location = 'someDefault.jpg'; 
    } 
    ?> 
在您的HTML身体

<img src="<?php echo $pic_location; ?>"/> 

这里假设你有完整的路径在URL .. 否则在前面加上回声之前的路径。

因此,如果图像存储在http://site.com/images

但是URL只显示那么imageName.jpg做到这一点

<img src="http://site.com/images/<?php echo $pic_location; ?>"/> 
+0

如果不是isset生成通知,请使用三元运算符来检查它 – Sam 2013-03-08 19:09:42

+0

好点Sam! – 2013-03-08 19:18:16

+0

如果不是$ set pic_location?男人只是做它 Sam 2013-03-08 19:20:17