Home > PHP > PHP-Showing image having name with “%2F”

PHP-Showing image having name with “%2F”

If you want to display an image on an HTML page, you can simply use the <img> tag. But if the image name consists of the html entity “%2F”, it is difficult to do that. For example:

The image name is : foo%2Fbar.png

<img src=”/images/foo%2Fbar.png” title=”image” alt=”image” />

The html page will try to get the image from the directory: /images/foo/bar.png

This way the page will never get the image and won’t be able to display that. I have a trick to solve this problem. Here it is:

<?php

<html>

<p>The correct image is:

<img src=”<?php echo substr_replace(“/images/foo%2Fbar.png”, ‘%252F’, -10, -7) ?>” alt=”image” title=”image” />

</html>

?>

This code will display the image by replacing “%2F” with “%252F” and you will not be blamed to have extra subdirectories.

Advertisements
Categories: PHP Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: