Jump to content


Photo

Php directories


  • Please log in to reply
8 replies to this topic

#1 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 July 2006 - 03:03 PM

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.c...older/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.c...folder/images?  While these would work, they aren't really good solutions.

#2 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 03:18 PM

use <img src="http://www.website.c...es/image1.jpg"> and so forth


#3 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 03:20 PM

<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...

#4 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 July 2006 - 03:24 PM

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.

#5 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 03:30 PM

will u always keep them in the same directory then..?

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

#6 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 July 2006 - 03:38 PM

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.

#7 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 03:43 PM

well i dont know if this helps wat i have is a config mile and i have

$images_url = "http://www.allinthis....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.allinthis....co.uk/images";

to

$images_url = "http://www.allinthis...o.uk/cabbages";

hope this is of any help.

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


#8 rshadarack

rshadarack
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 12 July 2006 - 03:47 PM

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.

#9 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 12 July 2006 - 03:51 PM

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..






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users