views:

57

answers:

3

hi

I usually use this line to import file from out of the current folder and it's work fine on my local host server

require("../DataBase.class.php");

but when I upload the script on my website I get this Warning

Warning: include(../DataBase.class.php) [function.include]: failed to open stream: No such file or directory

A: 

You're looking for the file in the parent directory. If you want it in the currently directory use:

require 'Database.class.php';

Perhaps on your local Webserver you have a copy in your parent directory for some reason that doesn't exist on your remote server.

cletus
I would agree with this as well...
John Nicely
+2  A: 

What's probably happening is that your include_path setting in php.ini is different on your server than on your local installation of PHP/Apache. Along with this, keep in mind that ../ doesn't point to the current directory that the file is in, it points to the parent directory of the current directory you are in. What I would advise is finding out the full path to your document root, then including your files like this:

<?php

$full_path = "/var/www/htdocs"; // this should be your website's full path
require( $full_path . "/DataBase.class.php" );

?>
John Nicely
Oh, and if you need to find out what the current directory is that your PHP script thinks it is in, use getcwd(). It will output the full path. Makes it easy to find the information you need!
John Nicely
+3  A: 

Safe mode doesn't like "../". So you should always use something like

require_once realpath(dirname(__FILE__) . '/..') . '/file.php';
raspi
This is a very informative aside.
Nerdling