Search code examples
phpphp-include

Failed to open stream no such file or directory. php


I've a file Profile.php which includes Profile_Control.php and the profile_control includes Profile_Model.php . Every things works fine till here.

I've another script named Upload.php from which data gets uploaded. This Upload.php also includes Profile_Control.php and as you know Profile_Control includes Profile_Model.php.Now I dont know why it is giving such an error.When the Profile.php loads it works fine but when I upload the data it says

Warning: include(../Model/Profile_Model.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\php\gagster\Control\Profile_Control.php on line 4

In Upload.php :

include_once("../../Control/Profile_Control.php");

In Profile.php :

include_once("../Control/Profile_Control.php");

In Profile_Control.php:

include_once("../Model/Profile_Model.php");

Document Structure:

 +-Control/
 |  |    
 |  +---- Profile_Control.php
 |
 +-Model/
 |  |
 |  +---- Profile_Model.php
 |
 +-Other/
    |
    +-- Upload/
           |
           +---- Upload.php

Solution

  • you can use the php file_exists() function to make sure that file is included if it is than do your stuff

    if (file_exists($filename)) {
        echo "The file $filename exists";
    } else {
        echo "The file $filename does not exist";
    }
    

    and use the

    defined('root') ? null : define('root', "url of your site "  ); 
    

    than

    include_once(root."rest of address");