PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 1st, 2005, 06:39 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 4
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:
require (../header.php); 
function. Is there a way to set the working directory of a required file so I don't have to redo header.php with absolute paths?

Last edited by Akdor 1154 : January 1st, 2005 at 06:42 PM. Reason: formatting was screwed

Reply With Quote
  #2  
Old January 2nd, 2005, 12:59 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
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.

Reply With Quote
  #3  
Old January 2nd, 2005, 09:00 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 4
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.

Reply With Quote
  #4  
Old January 3rd, 2005, 09:11 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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.

Reply With Quote
  #5  
Old January 3rd, 2005, 09:13 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
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...

Reply With Quote
  #6  
Old January 4th, 2005, 10:59 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 4
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

Reply With Quote
  #7  
Old January 5th, 2005, 12:10 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 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.

Reply With Quote
  #8  
Old January 5th, 2005, 08:42 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
I'm still confused... are we talking about <img> tags or require() functions?

Reply With Quote
  #9  
Old January 5th, 2005, 12:16 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
still talking about <img> tags.

Reply With Quote
  #10  
Old January 5th, 2005, 06:36 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 4
so is src=/images/image.gif an absolute path?? I though it had to have the host name as well. Oops.

Reply With Quote
  #11  
Old January 5th, 2005, 06:48 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
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.

Reply With Quote
  #12  
Old January 6th, 2005, 06:07 PM
Akdor 1154 Akdor 1154 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: Center Canyon in a Raptor
Posts: 34 Akdor 1154 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 44 sec
Reputation Power: 4
Ah, now I understand.
I thought absolute path and URL to be the same thing. Oops, indeed.

Quote:
Originally Posted by Marge Simpson
Now lets never speak of this again

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > require() in a different dir


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT