|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
require() in a different dir
Say I've got the directory structure:
Code:
+wwwroot |-+images | |-image1.gif | |-image2.gif | |-image3.gif | |-+dir1 | |-dirfile.php | |-header.php |-footer.php In header.php, I've got a page structure that uses images, and it uses the relative path to the images (images/image1.gif, etc). In dirfile.php, I've got a PHP Code:
Last edited by Akdor 1154 : January 1st, 2005 at 06:42 PM. Reason: formatting was screwed |
|
#2
|
|||
|
|||
|
It is best practice to code your html page so that absolute paths are used.
Instead of images/image1.gif you need to have /images/image1.gif. You really don't need to recode this, a simple search and replace should suffice. Is there a particular reason you need relative paths?
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
|
#3
|
|||
|
|||
|
Not really, I'm just lazy
![]() [backstory] I've arranged some of the Halo music for piano, and going on to the Seventh Column forums, and Rampancy.net I see that others have done so as well; so I'm trying to have a music database in my site, but preferably with the pages under their own directory (egag), e.g. Code:
+wwwroot |-+images | |-image.gif | |-+egag | |-upload.php | |-search.php | |-links.php | |-login.php | |-index.php |-about.php |-egag.php Note: this isn't hosted on my own server, i'm using a web hosting service. |
|
#4
|
||||
|
||||
|
I agree with laidbak. Absolute paths are could be your best option.
Otherwise, anything in your egag folder would have to call ../images in to access the images folder. I've tried playing with a "working directory" idea in PHP before... i found it to be more harm than good... not worth the hassel. |
|
#5
|
||||
|
||||
|
Hang on, on second thought why are you using require() with images?
i've set things like "halo_music_path" as a constant in a file called "config.php"... then require(halo_music_path."/page.php"); for example... |
|
#6
|
|||
|
|||
|
Is there a global to get the root directory, i.e. for me it'd be http://www.webhost.com/attic/ OR if I was testing on IIS, http://localhost/attic/
? I'm requireing a template that uses images as headers, border, etc. EDIT: How hard is it to make a work dir thingy? Is it just a function or do you need to do 'real' coding and stuff ? I'm only just beginning to get comfortable with PHP, and I don't feel like learning another language at this stage...is there a function like setworkdir(/egag) or setworkdir(../) that makes all relative paths point to inside that? Last edited by Akdor 1154 : January 4th, 2005 at 11:06 PM. Reason: Adding stuff |
|
#7
|
|||
|
|||
|
Working directory solutions are futile. I can gaurantee that. Absolute paths are the way to go.
Basically, if you are calling on one image in different ways (i.e. ../images/button.gif and ../../images/button.gif) you know you are going about it all wrong. The fact of the matter is, the path to that image is /images/button.gif, thus, each call to that image should be just that. Just try copying an html file from one directory that is several directories deep to a first level directory. If you have to modify the source of the html because the images don't work, you are doing it wrong. |
|
#8
|
||||
|
||||
|
I'm still confused... are we talking about <img> tags or require() functions?
|
|
#9
|
|||
|
|||
|
still talking about <img> tags.
|
|
#10
|
|||
|
|||
|
so is src=/images/image.gif an absolute path?? I though it had to have the host name as well. Oops.
|
|
#11
|
|||
|
|||
|
1 - /images/image.gif is an absolute path
2 - http://www.example.com/images/image.gif is a URL Which one is better and why? #1 is better because you can move the source file from server to server, domain to domain, and never have to change any code. |
|
#12
|
|||
|
|||
|
Ah, now I understand.
I thought absolute path and URL to be the same thing. Oops, indeed. Quote:
![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > require() in a different dir |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|