Jump to content

Warning: include failed to open stream: No such file or directory


johnmerlino

Recommended Posts

Hey all,

 

I viewed this tutorial and the guy used $_SERVER['DOCUMENT_ROOT'] to reference a view layout for his specific index file. So I tried to imitate and did exactly what he did, but for me I got the following error:

Warning: include(/Users/jmerlino/Sites/mark/public/diet/views/layouts/shop.php) [function.include]: failed to open stream: No such file or directory in /Users/jmerlino/Sites/diet/index.php on line 22

Warning: include() [function.include]: Failed opening '/Users/jmerlino/Sites/mark/public/diet/views/layouts/shop.php' for inclusion (include_path='.:/usr/lib/php') in /Users/jmerlino/Sites/diet/index.php on line 22

This is the php code that is causing this error:

include($_SERVER['DOCUMENT_ROOT'].'/'.'diet/views/layouts/'.$controller.'.php');

I'm not sure why it's going to:

/Users/jmerlino/Sites/mark/public/diet/views/layouts/shop.php

instead of:

/Users/jmerlino/Sites/diet/views/layouts/shop.php

 

Thanks for any response

Link to comment
Share on other sites

the reason it would do that is because of where to document root is set to( i think) you could also try:

include(__DIR__."/views/layouts/shop.php");

 

Yeah that worked. Still not sure how I would have been able to address $_SERVER['DOCUMENT_ROOT']. But I will use your solution for now. thanks.

Link to comment
Share on other sites

It's likely that your web host originally had a different folder structure set up and/or your account got moved to a different server and what you currently have for DOCUMENT_ROOT is the definition that was written to your vhosts file when your account was created. Your web host would need to correct the document root setting.

Link to comment
Share on other sites

I'm running this locally. Does that mean I have to find vhosts file locally? and I think am going to have to figure out what's wrong with the $_SERVER['DOCUMENT_ROOT'], because this:

include(__DIR__.'/'.'/views/'.$controller.'/'.$view.'.php'); //where $controller holds string shop and $view holds string index

produces this error:

Warning: include(/Users/jmerlino/Sites/diet/views/layouts//views/shop/index.php) [function.include]: failed to open stream: No such file or directory in /Users/jmerlino/Sites/diet/views/layouts/shop.php on line 19

when it should produce this:

/Users/jmerlino/Sites/diet/views/shop/index.php

 

 

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.