Jump to content

Archived

This topic is now archived and is closed to further replies.

rshadarack

Php directories

Recommended Posts

What I have right now is:

http://www.website.com/header.php - Writes the heading for every page on the site

Now I like to group similar files into folders, so I also have:

http://www.website.com/folder/file1.php

And I would like to use the header on it, so I have the code:

require("../header.php");

Problem is, header.php uses relative addressing for images, such as:

<img src="/images/image1.jpg">

So when in file1.php, it includes header.php, header.php then looks for images in http://www.website.com/folder/images instead of http://www.website.com/images.

Now changing the current working directory would solve this problem quite simply.  But I can't seem to find such a function for php.  Can php do this?  If not, can something else?  And if not, are there any other work arounds besides not using folders, using absolute address, and copying all the images to http://www.website.com/folder/images?  While these would work, they aren't really good solutions.

Share this post


Link to post
Share on other sites
<img src"full url">

put the full url with the http://www.mysite/ etc... where it says full url i can write it cause it shows an image thing...

Share this post


Link to post
Share on other sites
I know that, I addressed in the OP.  I don't like this option because if I decide to move my files around, I will have to go through pages and pages of url's, changing them all.

If I have no other option, it will probably be what I will do.  But I would like to know if there is a better option.

Share this post


Link to post
Share on other sites
will u always keep them in the same directory then..?

i mean... always in images somewhere...

Share this post


Link to post
Share on other sites
Most likely.  If I change that directory name, then I have no option but to go through my code changing all the urls.  What I wish to do is make it more flexible, so if I say move the entire site into a directory, everything will still work just fine using relative addressing.

As I said before, changing the current working directory would solve all my troubles.  Anyone know of a way to do this through php?  I can't seem to find any functions of this sort, so I'm thinking the answer is no.

Share this post


Link to post
Share on other sites
well i dont know if this helps wat i have is a config mile and i have

$images_url = "http://www.allinthissite.co.uk/images";

and then

<img src='".$images_url."/1.jpg'>

like that...

then if u move the folder to cabbages or something you can just change the

$images_url = "http://www.allinthissite.co.uk/images";

to

$images_url = "http://www.allinthissite.co.uk/cabbages";

hope this is of any help.

p.s. and obviously use the include('config.php'); in all the files with images

Share this post


Link to post
Share on other sites
What I didn't realize before was that my header.php script also includes another script.  So if I use absolute addressing, it goes through http, and thus, all the php code is ignored (if it isn't echo'ed).  So absolute addressing won't work.

Another thing I could do is make it so that any file that uses header.php is always one directory below it, and thus, the addressing "../someFolder/someFile" from within header.php will always work.

Edit: I never thought of doing such a thing, but keeping file address in php variables would make scripts much for flexible and easier to maintain/update.  Thanks.

Share this post


Link to post
Share on other sites
no problems glad to be of help, i use to do it all the old way and include the links in all the images then i thought about it and came up with that..

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.