【问题标题】:Load pictures in php file在php文件中加载图片
【发布时间】:2013-02-24 10:27:04
【问题描述】:

我想在 PHP 中执行以下操作

我的目录中有图片,我需要使用 "site.com/image.php?pic=xx/xx.jpg" 将图片加载到 php 文件清理页面中

例如: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;
}

?>

如果有人能帮忙那就太好了 谢谢!

【问题讨论】:

  • What have you tried?你还需要更多细节。使用$_GET在 PHP 中加载图像的方法有很多@

标签: php jpeg image


【解决方案1】:
    <?php
    if (isset($_GET['pic'])){
       $pic_location = $_GET['pic'];
    }
    else {
       $pic_location = 'someDefault.jpg';
    }
    ?> 

在您的 html 正文中:

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

这假设您在 url 中有完整路径.. 否则在 echo 之前添加路径。

所以如果图片存储在http://site.com/images

但网址仅显示 imageName.jpg 然后执行此操作

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

【讨论】:

  • 如果不是isset生成通知,使用三元运算符进行检查
  • 如果不是 isset $pic_location?男人就这样做 "/>
  • 我需要类似的东西,但可以工作! freeminecraftaccount.org/image.php?pic=images/minecraft.jpg
  • 显示第 70 - 73 行的 php 代码,您在其中指定图像 src="/"
  • 为降低 XSS 漏洞,请清理输入!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-12
  • 2011-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多