How to get imageurl from the url? So it can show the image I want in the page
So I have this page .html , .php, whatever, It's a page with my logo, some ads, menus etc. I want this page to show the image I want, Let's say I have /images/ima开发者_如何学Cge1.jpg and I want to sent it to someone, but I want that person to see it in my website so I would so something like mypage.com/example.php(somecodehere?)/images/image1.jpg
And it would open example.php (or .html) with image1.jpg displaying where I had my code (let's say in the middle)
Any simple way to do this?
Thanks
You should use the $_GET to get the image:
www.exapmle.com/page.php?imagename=image1.jpg => simple example for the page.php code
<?php
echo "<img src=\"{$_GET["imagename"]}\">";
?>
Be aware that this is a dangerous code and you should always check the input from the user.
You need to use $_GET[] in order to get the image path. Lets say that your link is:
http://blabla.com/example.php?img=image1.jpg
Now, you need to get that img value:
$img = $_GET["img"];
Now you have the image that you want to display :)
So, from my understanding you have an images hosted on your website that you wish to share with people via a link of some sort?
If so, the best way to do this is would be via GET variables. For example, if you had an image called : holiday.jpg, the link would be:
http://domain.com/example.php?img=holiday.jpg
Therefore within your web page example.php (must have the .php ext) you would have something along the lines of :
<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>
Note
Be careful not to have slashes in your GET variable eg: /image/directory/holiday.jpg . Properly escape this by replace dashes with %2F
精彩评论