Archive for June, 2008

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

June 26, 2008 Leave a comment

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:



<p>The correct image is:

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



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

Categories: PHP Tags: