require_once error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dhananjay
Forum Newbie
Posts: 1
Joined: Mon Mar 17, 2008 11:27 pm

require_once error

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: require_once error

Post 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".
(#10850)
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: require_once error

Post 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?
devendra-m
Forum Contributor
Posts: 111
Joined: Wed Sep 12, 2007 3:16 am

Re: require_once error

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