Page 1 of 1

require_once error

Posted: Mon Mar 17, 2008 11:33 pm
by dhananjay
Inspite of file present there right position,this error comes.
Warning: require_once(/web/functions.php) [function.require-once]: failed to open stream: No such file or directory in /opt/lampp/htdocs/peer/web/includes/page.php on line 23

Re: require_once error

Posted: Mon Mar 17, 2008 11:58 pm
by Christopher
If it says you have the path wrong, you probably have it wrong.

Try the absolute path "/opt/lampp/htdocs/peer/web/functions.php".

Re: require_once error

Posted: Mon Mar 17, 2008 11:59 pm
by RobertGonzalez
Show the code that is calling require_once. Also take note that when you put the leading slash on the file name the web server looks in its document root for the file, so the file is being looked for at http://localhost/web/functions.php. Is that where the file is?

Re: require_once error

Posted: Tue Mar 18, 2008 1:51 am
by devendra-m
for those path problems use following file the file is absolutePath.php

Code: Select all

<?  
    # Created by: Devendra Maharjan ( devendra@wlinktech.com,devendra-m@hotmail.com,devendram@gmail.com )
    
    /*
        Instructions to use :
        
        Place this file in a folder to make it a root.
        
        function absolutePathServer($destination)
         -  Pass relative path of a file to be found to function absolutePathServer() and get absolute server path.
         -  If you give test/test.php as parameter. The output will be as /php/test/test.php.
         -  Use : to include php pages.
         
        function absolutePathClient($destination)
         -  Pass relative path of a file to function absolutePathClient() and get absolute client path.
         -  If you give test/test.php as parameter. The output will be as http://www.test.com/test/test.php
         -  Use : to include any client related file. eg javascript,image,css.          
    */
    define(ROOT_PATH,ereg_replace("^(.*)/(.*)$","\\1",str_replace('\\','/',__FILE__)));
 
    function traverse($root,$destination)
    {
        if(is_dir($root))
        {
            $handle = opendir($root);
            while (false !==($file=readdir($handle))) 
                if($file != '.' && $file != '..')
                {
                    $full_path=$root."/".$destination;              
                    if(file_exists($full_path))             
                        return $full_path;
                            
                    $path=$root."/".$file;
                    if($full_path=traverse($path,$destination))
                        return $full_path;
                }
        }
    }
    function absolutePathServer($destination)
    {
        if($full_path=traverse(ROOT_PATH,$destination))
            return $full_path;
        else 
            return $destination;
    }
    function absolutePathClient($destination)
    {
        if($full_path=traverse(ROOT_PATH,$destination))
            return "http://".str_replace('//','/',str_replace($_SERVER['DOCUMENT_ROOT'],$_SERVER['HTTP_HOST']."/", $full_path));
        else 
            return $destination;
    }
?>
 
use:
Place this file in a root folder then include this file and use a function absolutePathServer as below

Code: Select all

require("absolutePath.php");
require(absolutePathServer("folder/page.php"));