linking to a folder higher up in the hierarchy

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sumwutt
Forum Newbie
Posts: 5
Joined: Mon Nov 10, 2008 12:35 pm

linking to a folder higher up in the hierarchy

Post by sumwutt »

Ok, so I am trying to link to an image that is in a folder that is higher up in the hierarchy. I have set the file permissions on both the folder and the image to 0755. I have not had any problems linking to images in the same folder.

Here is the img tag I am using:

echo "<img src ='../../../../uploads/dragonBanner.jpg' style ='margin-bottom: 25px' alt ='user added banner' title ='user added banner' /><br />";

The ../'s are the correct amount, and when the page displays I get the alt content.

Any ideas would be much appreciated...

Thanks,
SuMWuTT
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: linking to a folder higher up in the hierarchy

Post by requinix »

Try browsing to the image itself and see what happens.
sumwutt
Forum Newbie
Posts: 5
Joined: Mon Nov 10, 2008 12:35 pm

Re: linking to a folder higher up in the hierarchy

Post by sumwutt »

Tried that but the uploads folder is above the www entry folder from the web. So I can't get to it from the browser.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: linking to a folder higher up in the hierarchy

Post by Mark Baker »

sumwutt wrote:Tried that but the uploads folder is above the www entry folder from the web. So I can't get to it from the browser.
If it's outside of the web server root, then you can't access it using the img tag <img src="../img.gif"> unless you write a little script that can read outside of the web server root and use <img src="imgScript?img=../img.gif">
User avatar
Syntac
Forum Contributor
Posts: 327
Joined: Sun Sep 14, 2008 7:59 pm

Re: linking to a folder higher up in the hierarchy

Post by Syntac »

Rule of thumb: If you can't access it by typing the URL into the browser, you can't access it with an HTML tag.

In order to make a script output the image, try something like the following:

Code: Select all

$image_data = file_get_contents( "path/to/image.png" );
header( "Content-type: image/png" ); // You'll need to change this to the appropriate MIME type, of course.
echo $image_data;
sumwutt
Forum Newbie
Posts: 5
Joined: Mon Nov 10, 2008 12:35 pm

Re: linking to a folder higher up in the hierarchy

Post by sumwutt »

thank you,

I will try this, although I am not sure how to apply this to the code I am using.

sumwutt
sumwutt
Forum Newbie
Posts: 5
Joined: Mon Nov 10, 2008 12:35 pm

Re: linking to a folder higher up in the hierarchy

Post by sumwutt »

I had some trouble implementing your code syntac, but I did find a place in the hierarchy that the upload took and I could access it using my original code.

I will continue to work on the code you gave me though as I can't stand to give up on anything.

thanx for help all it was much appreciated.
Post Reply