Jump to content

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.
Link to comment
https://forums.phpfreaks.com/topic/14390-php-directories/
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.
Link to comment
https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56787
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.
Link to comment
https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56795
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
Link to comment
https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56801
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.
Link to comment
https://forums.phpfreaks.com/topic/14390-php-directories/#findComment-56802
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.