Question

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

Was it helpful?

Solution

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

require_once realpath(dirname(__FILE__) . '/..') . '/file.php';

OTHER TIPS

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" );

?>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top