PHP Includes

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Fri Oct 06, 2006 6:56 pm    Post subject: PHP Includes Reply with quote

I am making a new website in PHP, and i have made a script that includes all of the files in one directory (so its easyer to edit things like mysql username and passwords) I have now come to add some more sub-directorys to the site and i get the message "Could not find the folder 'res/'" I have attempted to add ../ on to the begining of the name and that does not work.

I was wondering if there anything else i can do?
_________________
My online Portfolio
Back to top View user's profile Send private message Send e-mail MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Fri Oct 06, 2006 7:27 pm    Post subject: Reply with quote

Use just "/folder/filename.ext" just / will always start in the root folder.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Fri Oct 06, 2006 7:30 pm    Post subject: Reply with quote

I have just tried that and PHP gives this error

Quote:

Warning: opendir(/res/) [function.opendir]: failed to open dir: Invalid argument in D:\! Shroodoo\www\require_master.php on line 8

_________________
My online Portfolio
Back to top View user's profile Send private message Send e-mail MSN Messenger
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Oct 06, 2006 7:44 pm    Post subject: Reply with quote

Try using a relative path instead. Here's an example:

Code:
<?php
include("folder/filename.ext");
?>
Back to top View user's profile Send private message Visit poster's website
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Fri Oct 06, 2006 8:22 pm    Post subject: Reply with quote

:|
I have made a code to include all of the files in a folder and it will automatically include them, if they have a specific ending.
_________________
My online Portfolio
Back to top View user's profile Send private message Send e-mail MSN Messenger
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Fri Oct 06, 2006 8:33 pm    Post subject: Reply with quote

Remember that every link, including images, etc must all start with / for it to work. My site works this way and it works well.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Fri Oct 06, 2006 10:33 pm    Post subject: Reply with quote

AbyssUnderground wrote:
Remember that every link, including images, etc must all start with / for it to work. My site works this way and it works well.


That works well on the internet where the root folder is www.abyssunderground.co.uk/

But on the harddrive the root folder is C:\

What I do is create a variable called $basepath
I then put the full path to the folder in the variable
for you this would be C:\Program Files\Abyss Webserver\htdocs\

Then just add this to the start of all variables that require a file eg
Code:
<?php
$basepath = "C:\\Program Files\\Abyss Webserver\\htdocs";
$file = $basepath ."\\includes\\include.txt";

print $file;
?>

The output of this would be:
Quote:

C:\Program Files\Abyss Webserver\htdocs\includes\include.txt


Notice that in the variables I have used a double back-slash (\) this is because php uses the \ to escape characters. so you need to use a \ to escape a \
You may be able to use a forward-slash (/) instead of the back-slash.

If you are using relative paths then /includes/ would be C:\includes\ but includes/ would be the folder includes in the current folder

Does that help?

Edit:
In php there is the constant __FILE__ that holds the full path and filename of the file
you will then be able to use either dirname() and/or basename() to get the current directory to include extra files
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Sat Oct 07, 2006 1:13 pm    Post subject: Re: PHP Includes Reply with quote

abyssisthebest,

Either use the full path of the files to include (may be using the __FILE__ and dirname() functions to not hardcode the paths), or add the paths where include files may be in php.ini (include_path) as in:

Code:
include_path = ".;c:\mysite\includes"


The directory paths are separated by a ; character. The . special directory means that include will also search for the included file relatively to the script directory.
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Sat Oct 07, 2006 1:15 pm    Post subject: Reply with quote

I dont see why its not working for him. All I used was a simple / at the beginning of all filenames linked to like images would be /images/image.ext and links /dir/file.ext. My error page was the main reason I converted everything to include the / because it would only work in the root folder otherwise all the images would be missing in folders.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
abyssisthebest
-


Joined: 30 Jun 2005
Posts: 319
Location: Boston, UK

PostPosted: Sat Oct 07, 2006 2:31 pm    Post subject: Reply with quote

thanks aprelium, that works.

I have used the / on all of the images and that, it just didnt seam to work on my php code.
_________________
My online Portfolio
Back to top View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group