southampton_web_designer Posted August 26, 2009 Share Posted August 26, 2009 Hi All, My directory is /home/username/public_html/ In this directory i have: index.php, 'views' folder I want to access /home/username/public_html/views/layouts/jobs.php Within index.php, code wriiten is: require('../'.'views/layouts/'.$controller.'.php'); Error are: Warning: require(../views/layouts/jobs.php) [function.require]: failed to open stream: No such file or directory in /home/username/public_html/index.php on line 54 Fatal error: require() [function.require]: Failed opening required '../views/layouts/jobs.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/public_html/index.php on line 54 Kind help how to solve this problem. Thank you Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/ Share on other sites More sharing options...
mikesta707 Posted August 26, 2009 Share Posted August 26, 2009 require('/views/layouts/'.$controller.'.php'); the ../ means to go up a folder I believe Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907052 Share on other sites More sharing options...
southampton_web_designer Posted August 26, 2009 Author Share Posted August 26, 2009 When I used require('/views/layouts/'.$controller.'.php'); the error is Fatal error: require() [function.require]: Failed opening required '/views/layouts/jobs.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/username/public_html/index.php on line 54 Problem not solved Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907063 Share on other sites More sharing options...
mikesta707 Posted August 26, 2009 Share Posted August 26, 2009 are you sure that file exists then? if the views folder is in the same directory as your index.php page, then its going to the right folder... try the whole url, like mysite.com/views/otherfolder/jobs.php Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907071 Share on other sites More sharing options...
southampton_web_designer Posted August 26, 2009 Author Share Posted August 26, 2009 Yes file do exists. But jobs.php has a code: <?php require('/views/'.$controller.'/'.$view.'.php'); ?> and $controller is 'jobs' and $view is one of the options of case statement. Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907077 Share on other sites More sharing options...
mikesta707 Posted August 26, 2009 Share Posted August 26, 2009 well then try the whole url, as in <?php require('mysite.com/views/'.$controller.'/'.$view.'.php'); ?> and if that doesn't work than the files either don't exist, or don't exist where you think they exist Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907082 Share on other sites More sharing options...
Alex Posted August 26, 2009 Share Posted August 26, 2009 You can use file_exists() to confirm that the file exists in the location you're requesting it from. Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907097 Share on other sites More sharing options...
southampton_web_designer Posted August 26, 2009 Author Share Posted August 26, 2009 Ok Guys, Problem is solved. Solution is: require_once('/home/username/public_html'.'/views/layouts/'.$controller.'.php'); in index.php Actually my site is on a free webserver and probably that's why this was required: '/home/username/public_html' Anyway many thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/172019-solved-how-to-use-require-problem/#findComment-907117 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.