Jump to content

PHP error: failed to open stream


bugzy

Recommended Posts

Hello guys I'm just a beginner and I have been idle on programming for almost a year already and I find myself confuse again.

 

I'm getting this error

 

Warning: require_once(back/includes/connection.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\back\admin\index.php on line 1

 

Fatal error: require_once() [function.require]: Failed opening required 'back/includes/connection.php' (include_path='.;C:\php5\pear') in C:\wamp\www\back\admin\index.php on line 1

 

 

I know it's a path problem and I almost tried everything and I still can't figure it out.

 

So basically I have folder "admin" and a file "index" where I'm calling for the file "connection.php" which is on the folder "includes" on the root folder...

 

Anyone?

Link to comment
Share on other sites

What is the full path to the page you're loading and the ful path to the file you're trying to include?

 

You can include pages one of two ways, relatively or full path.

 

Relatively:  the location from the current file.  This is the most common and when you see things like ../assets/

Full Path:  the path from root / c:

Link to comment
Share on other sites

Sorry guys need to unsolved it because my problem now is related to to this..

 

I'm using a single CSS only which is on the stylesheet folder. So when my index.css is on the root I'm calling it like this

 

<link rel="stylesheet" type="text/css" href="stylesheet/public.css" media="screen" />

 

problem is when I'm calling that CSS file on another folder, it can't find it because I'm using the same header as my files in the root directory.. As much as possible I want to use one CSS only.

 

I don't want to use any php yet because the problem might only be on the path only..

 

 

Anyone? thanks!

Link to comment
Share on other sites

Well, its kinda hacky, but you can define the absolute path to your CSS file, and then use the absolute path of the current file to make a relative link.

 

Here's a snippet from SO, in use.

http://stackoverflow.com/questions/2637945/getting-relative-path-from-absolute-path-in-php

<?php

$css = '/path/to/webroot/css/main.css';
$current = '/path/to/webroot/html/thisfile.html';
// you could use $_SERVER['SCRIPT_FILENAME'] for $current

echo getRelativePath($current, $css);
// outputs ../css/main.css

function getRelativePath($from, $to) {
    $from     = explode('/', $from);
    $to       = explode('/', $to);
    $relPath  = $to;

    foreach($from as $depth => $dir) {
        // find first non-matching dir
        if($dir === $to[$depth]) {
            // ignore this directory
            array_shift($relPath);
        } else {
            // get number of remaining dirs to $from
            $remaining = count($from) - $depth;
            if($remaining > 1) {
                // add traversals up to first matching dir
                $padLength = (count($relPath) + $remaining - 1) * -1;
                $relPath = array_pad($relPath, $padLength, '..');
                break;
            } else {
                $relPath[0] = './' . $relPath[0];
            }
        }
    }
    return implode('/', $relPath);
}

?>

Link to comment
Share on other sites

Well, its kinda hacky, but you can define the absolute path to your CSS file, and then use the absolute path of the current file to make a relative link.

 

Here's a snippet from SO, in use.

http://stackoverflow.com/questions/2637945/getting-relative-path-from-absolute-path-in-php

<?php

$css = '/path/to/webroot/css/main.css';
$current = '/path/to/webroot/html/thisfile.html';
// you could use $_SERVER['SCRIPT_FILENAME'] for $current

echo getRelativePath($current, $css);
// outputs ../css/main.css

function getRelativePath($from, $to) {
    $from     = explode('/', $from);
    $to       = explode('/', $to);
    $relPath  = $to;

    foreach($from as $depth => $dir) {
        // find first non-matching dir
        if($dir === $to[$depth]) {
            // ignore this directory
            array_shift($relPath);
        } else {
            // get number of remaining dirs to $from
            $remaining = count($from) - $depth;
            if($remaining > 1) {
                // add traversals up to first matching dir
                $padLength = (count($relPath) + $remaining - 1) * -1;
                $relPath = array_pad($relPath, $padLength, '..');
                break;
            } else {
                $relPath[0] = './' . $relPath[0];
            }
        }
    }
    return implode('/', $relPath);
}

?>

 

Thanks. I'll definitely try this.

 

Btw is this the standard? How are you guys doing it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.