johnmerlino Posted September 1, 2010 Share Posted September 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/ Share on other sites More sharing options...
ldb358 Posted September 1, 2010 Share Posted September 1, 2010 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"); Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/#findComment-1105956 Share on other sites More sharing options...
johnmerlino Posted September 1, 2010 Author Share Posted September 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/#findComment-1106016 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/#findComment-1106021 Share on other sites More sharing options...
johnmerlino Posted September 1, 2010 Author Share Posted September 1, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/#findComment-1106034 Share on other sites More sharing options...
johnmerlino Posted September 1, 2010 Author Share Posted September 1, 2010 I used this as a temporary fix: $_SERVER["DOCUMENT_ROOT"] = '/Users/jmerlino/Sites/'; in my main index.php file. I know it's terrible solution but the apache config is huge and I'm not exactly sure where to look in order to make the change to document root. Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/#findComment-1106040 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2010 Share Posted September 1, 2010 Search for: DocumentRoot Quote Link to comment https://forums.phpfreaks.com/topic/212243-warning-include-failed-to-open-stream-no-such-file-or-directory/#findComment-1106042 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.