thientanchuong Posted December 4, 2013 Share Posted December 4, 2013 Hi guys, I am studying on how to code php n mysql by Model Control View concept First of all, I created some files and some folder containers as the picture below My main point to add category data into my database so I have database.php in model folder categoryController.php in controller folder addCategory.php in categoryController.php, I got first problem to open a stream to where I stated in code then I even remove triple dots in line 4 but It does not work. Could any one help me out with the solution please ? Kind Regards Quote Link to comment https://forums.phpfreaks.com/topic/284505-could-not-open-stream-from-different-folder/ Share on other sites More sharing options...
thientanchuong Posted December 4, 2013 Author Share Posted December 4, 2013 (edited) Sorry, I do not know why it does not load the two photos in previous post and there is no edit function so people can see my photos of coding problem overhere Hi guys, I am studying on how to code php n mysql by Model Control View concept First of all, I created some files and some folder containers as the picture below My main point to add category data into my database so I have database.php in model folder categoryController.php in controller folder addCategory.php in categoryController.php, I got first problem to open a stream to where I stated in code then I even remove triple dots in line 4 but It does not work. Could any one help me out with the solution please ? Kind Regards Edited December 4, 2013 by thientanchuong Quote Link to comment https://forums.phpfreaks.com/topic/284505-could-not-open-stream-from-different-folder/#findComment-1461181 Share on other sites More sharing options...
DavidAM Posted December 4, 2013 Share Posted December 4, 2013 include('.../models/database.php'); should only be TWO DOTS not THREE. But that's not going to fix it. When using relative paths for include (the ../) it is relative to the SCRIPT THAT IS RUNNING not the file doing the include. If the running script is admin/addNewCategory.php then the include would be include('models/database.php'). Of course using relative paths can be troublesome. Once you fix it as above, if you later try to include the controller from, oh say "admin/secret/hideFromUser.php", then the relative path would need to be include('../models/database.php'); which would then cause the other script to fail. I usually define an set of constants in my bootstrap (or other common include file) that has absolute references and then use the constant for all includes: bootstrap.php define('C_PHP_INCLUDE_DIR', '/path/to/include/base/');all php scripts include('./bootstrap.php'); include(C_PHP_INCLUDE_DIR . 'models/database.php');Then I put a link (not a copy) to the bootstrap file in all execution directories. This way, I can maintain the absolute paths in a single file and all code uses the same path. Quote Link to comment https://forums.phpfreaks.com/topic/284505-could-not-open-stream-from-different-folder/#findComment-1461293 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.