NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page PHP includes refererencing files from different directory thread

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-07-2005, 02:36 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Mar 2005
Posts: 36
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.
????: NamePros.com http://www.namepros.com/programming/73891-php-includes-refererencing-files-different-directory.html

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, 11:06 PM   #2 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



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.
????: NamePros.com http://www.namepros.com/showthread.php?t=73891

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.

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-08-2005, 12:14 AM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Mar 2005
Posts: 36
FreeBaGeL is an unknown quantity at this point
 



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.
????: NamePros.com http://www.namepros.com/showthread.php?t=73891

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, 01:14 AM   #4 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



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.
????: NamePros.com http://www.namepros.com/showthread.php?t=73891

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, 09:24 AM THREAD STARTER               #5 (permalink)
NamePros Member
Join Date: Mar 2005
Posts: 36
FreeBaGeL is an unknown quantity at this point
 



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, 09:47 AM   #6 (permalink)
Senior Member
Join Date: May 2003
Posts: 2,187
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, 01:10 PM   #7 (permalink)
Senior Member
Join Date: Aug 2002
Posts: 1,255
deadserious has a spectacular aura aboutdeadserious has a spectacular aura about
 



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.
????: NamePros.com http://www.namepros.com/showthread.php?t=73891

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


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

Liquid Web Smart Servers  
All times are GMT -7. The time now is 12:03 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger