如何从url获取imageurl ?这样它就能在页面上显示我想要的图像


How to get imageurl from the url? So it can show the image I want in the page

这个页面是。html,。php,这是我的logo,一些广告,菜单等。我想让这个页面显示我想要的图像,假设我有/images/image1。jpg我想把它发给别人,但我想让那个人在我的网站上看到它所以我想这样mypage.com/example.php (somecodehere ?)/图片/image1.jpg

它会打开example。php(或。html)并显示image1.jpg显示我的代码(比如在中间)

有什么简单的方法吗?

谢谢

您应该使用$_GET来获取图像:

www.exapmle.com/page.php?imagename=image1.jpg => simple example for the page.php code
<?php
   echo "<img src='"{$_GET["imagename"]}'">";
?>

请注意,这是一个危险的代码,您应该始终检查用户的输入

您需要使用$_GET[]来获取图像路径。假设你的链接是:

http://blabla.com/example.php?img=image1.jpg

现在,您需要获取img值:

$img = $_GET["img"];

现在你有了你想要显示的图像:)

那么,从我的理解,你有一个图片托管在你的网站上,你希望通过某种形式的链接与人们分享?

如果是这样,最好的方法是通过GET变量。例如,如果您有一个名为:holiday.jpg的图像,那么链接将是:

http://domain.com/example.php?img=holiday.jpg

因此,在你的网页example.php(必须有。php ext)中,你会有这样的内容:

<html>
  <head>
    <title>IMG SITE</title>
  </head>
  <body>
    <div class="content">
     <?php
     if(isset($_GET["img"])) echo '<img src="/images/directory/'.$_GET["img"].'">';
     ?>
    </div>
  </body>
</html>
<标题>注意

注意不要在GET变量中使用斜杠,例如:/image/directory/holiday.jpg。通过将破折号替换为%2F

来正确转义。