[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 03-07-2005, 01:36 PM   #1 (permalink)
NamePros Member
 
Join Date: Mar 2005
Posts: 33
53.00 NP$ (Donate)

FreeBaGeL is an unknown quantity at this point


PHP includes refererencing files from different directory

Ok, here's the deallio.

I've got several domains, some of them reference the same files. For example's sake, we'll call the current directory I'm working in "current."

The directory structure has all the domains on the same level, so I use for instance, the same footer file in each domain. Just say to keep things simple in this case that Util is a domain on the same level as all the others.

So, I've just been referencing it with for instance

Code:
include "../../Util/public_html/footer.html";
This works fine. However, I've run into an issue when I try to include a file that contains other files (in particular images) that it refers to.

For instance I have a file called "navHeaders.html" that calls a few images inside of it. These images are in the same dir as navHeaders, the Util dir. So I have

Code:
include "../../Util/public_html/navHeaders.html";
This calls the navHeaders file just fine, but all of the images are broken since it's looking for them in the dir I'm working in (current) even though the file that's calling them is in a different directory. navHeaders calls simply "image.jpg" Shouldn't it look for this in the directory navHeaders is in? Is there any way to get around this without having to upload all the images into my current working directory (since that defeates the purpose of all these different domains referrincing the same file anyway)?

Thanks in advance.
FreeBaGeL is offline  
Old 03-07-2005, 10:06 PM   #2 (permalink)
Senior Member
 
Join Date: Aug 2002
Posts: 1,300
2.85 NP$ (Donate)

deadserious has a spectacular aura aboutdeadserious has a spectacular aura about


Quote:
Originally Posted by FreeBaGeL
This works fine. However, I've run into an issue when I try to include a file that contains other files (in particular images) that it refers to.

For instance I have a file called "navHeaders.html" that calls a few images inside of it. These images are in the same dir as navHeaders, the Util dir. So I have

Code:
include "../../Util/public_html/navHeaders.html";
In your example, the navHeaders.html file would actually be located in the public_html directory and not the Util dir.

Quote:
Originally Posted by FreeBaGeL
This calls the navHeaders file just fine, but all of the images are broken since it's looking for them in the dir I'm working in (current) even though the file that's calling them is in a different directory. navHeaders calls simply "image.jpg" Shouldn't it look for this in the directory navHeaders is in? Is there any way to get around this without having to upload all the images into my current working directory (since that defeates the purpose of all these different domains referrincing the same file anyway)?

Thanks in advance.
Yes it will look in the same directory that navHeaders is in, but from your example this would actually be the public_html directory. So if you had <image src=image.jpg"> in the navHeaders.html file it would look for image.jpg in the public_html directory. You'll need to put files that are directly accessed like this inside a web accessible directory anyway.
deadserious is offline  
Old 03-07-2005, 11:14 PM   #3 (permalink)
NamePros Member
 
Join Date: Mar 2005
Posts: 33
53.00 NP$ (Donate)

FreeBaGeL is an unknown quantity at this point


Quote:
Originally Posted by deadserious
Yes it will look in the same directory that navHeaders is in, but from your example this would actually be the public_html directory. So if you had <image src=image.jpg"> in the navHeaders.html file it would look for image.jpg in the public_html directory. You'll need to put files that are directly accessed like this inside a web accessible directory anyway.
That was just a typo when making the post, when I said it was in the Util dir I meant the Util/public_html dir.

The navHeaders.html file, as well as the image.jpg file are both in Util/public_html. But when I include navHeaders.html from a dir called, say, "CurrentDir" I'll get an error that CurrentDir/image.jpg cannot be found.

It should be also noted, not sure if I mentioned it in my original post, that the examples we're using of Util and CurrentDir are actually domains, not just directories, but in my ftp client they're handled the same as directories, and all of the domains are on the same level in the hierarchy.
FreeBaGeL is offline  
Old 03-08-2005, 12:14 AM   #4 (permalink)
Senior Member
 
Join Date: Aug 2002
Posts: 1,300
2.85 NP$ (Donate)

deadserious has a spectacular aura aboutdeadserious has a spectacular aura about


Quote:
Originally Posted by FreeBaGeL
That was just a typo when making the post, when I said it was in the Util dir I meant the Util/public_html dir.

The navHeaders.html file, as well as the image.jpg file are both in Util/public_html. But when I include navHeaders.html from a dir called, say, "CurrentDir" I'll get an error that CurrentDir/image.jpg cannot be found.

It should be also noted, not sure if I mentioned it in my original post, that the examples we're using of Util and CurrentDir are actually domains, not just directories, but in my ftp client they're handled the same as directories, and all of the domains are on the same level in the hierarchy.
Oh I see what you're saying now. That's because when you're including the file from another directory, the html output of the file you're including is simply the same, so it will be calling the image.jpg file from CurrentDir/image.jpg.

You would have to change the path of your image(s) in your html. The easiest way would probably be to just use the full url to your images in the html rather than the relative path.
deadserious is offline  
Old 03-08-2005, 08:24 AM   #5 (permalink)
NamePros Member
 
Join Date: Mar 2005
Posts: 33
53.00 NP$ (Donate)

FreeBaGeL is an unknown quantity at this point


Quote:
Originally Posted by deadserious
The easiest way would probably be to just use the full url to your images in the html rather than the relative path.
so like "http://www......" ?

Is that ok to do, will it slow down the page loading or anything like that?
FreeBaGeL is offline  
Old 03-08-2005, 08:47 AM   #6 (permalink)
Senior Member
 
Join Date: May 2003
Posts: 2,211
6,170.25 NP$ (Donate)

adam_uk is a jewel in the roughadam_uk is a jewel in the roughadam_uk is a jewel in the rough

Breast Cancer
dont use the full url edit you build your pages do this

say you have an image called dave.gif and you want to insert it

use this code
<img src="/images/some/other/path" height=blah width=blah>

so if your file is being included in
/dave/1/3/qwetty/
or
/index.html

it will always work it works because the first slash inside the / tells the browsers to request files from the root directory so it doesnt matter where you place images.
adam_uk is offline  
Old 03-08-2005, 12:10 PM   #7 (permalink)
Senior Member
 
Join Date: Aug 2002
Posts: 1,300
2.85 NP$ (Donate)

deadserious has a spectacular aura aboutdeadserious has a spectacular aura about


Quote:
Originally Posted by FreeBaGeL
so like "http://www......" ?

Is that ok to do, will it slow down the page loading or anything like that?
Yes, that's okay to do, and it won't slow down the page loading or anything, the only thing is you'd need to change it if you ever moved your site to a new domain or something like that.

What adam_uk suggested would also work if you had a copy of whatever images/files you needed in each domains public_html directory. Because like he said, it will always request the files from the root directory. But the problem is it will be the root directory of that particular domain so you would need a copy of the images in each domains public_html directory. If you only wanted to have one set of images in just one of the domains public_html directories or somewhere else, the easiest way would probably be to use the full url which is why I suggested that way.
deadserious is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tutorial: Getting started with PHP (The Basics) deadserious Webmaster Tutorials 60 11-17-2007 11:35 AM
HOWTO: Install the Apache Web Server, Perl, PHP, and MySQL on Windows deadserious Webmaster Tutorials 96 05-27-2007 01:24 PM
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM
Tutorial: How to Install Apache2 MySQL and PHP on Windows deadserious Webmaster Tutorials 35 09-21-2005 09:46 PM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:24 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85