Jump to content

Could not open stream from different folder


thientanchuong

Recommended Posts

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

 

11200842655_62eee88d5d_b.jpg

 

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

 

11200938716_7a416d5851_b.jpg

 

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

Link to comment
Share on other sites

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

 

11201349075_49b2b2612e_o.png

 

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

 

11201475653_af46498ece_o.png

 

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 by thientanchuong
Link to comment
Share on other sites

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.
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.