11

This might just come as a very silly question, but i am really frustrated of this not working. I have a home file (home.php) which has contains <? include ("/production/fetch_order.php"); ?>. As it can be seen i am trying to access a file from home.php. The file is named as fetch_order.php which is in the production folder. My path is correct, the spellings are absolutely correct too. However i end up with this error:

Warning: include(/production/fetch_order.php) [function.include]: 
failed to open stream: No such file or directory in /path/to/home.php on line 119

Warning: include() [function.include]: Failed opening '/production/fetch_order.php'
for inclusion (include_path='.:/path/to/php/php5.3.6/lib/php') in
/path/to/home.php on line 119
Owen Blacker
  • 3,889
  • 2
  • 33
  • 68
Namit
  • 1,264
  • 7
  • 18
  • 34
  • One often runs into this error, and to quickly troubleshoot it, follow these steps : http://stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 17:02
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew Apr 30 '16 at 14:24

3 Answers3

14

You are using an absolute path (/) at the start of the line, you need to remove that slash and it would be a relative path, example:

production/fetch_order.php

When adding a slash, it starts at the root directory of your system, without it, it looks in the current directory.

MacMac
  • 30,042
  • 53
  • 142
  • 217
  • Does the file *actually* exists or you need to enter the correct path to the file. Is there a folder named `production` in the same directory where `home.php` is? – MacMac Mar 04 '12 at 19:14
  • The file does exist. The home.php and the production folder are at the same level, and the production folder has a file named fetch_order.php – Namit Mar 04 '12 at 19:15
  • There is now a troubleshooting checklist for this frequent error here : stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 17:02
  • Yes PHP7 spits a warning about the trailing slash while other versions of PHP don't. Thanks for the answer – Thanasis Dec 26 '18 at 12:43
5

Make sure that the path you're referencing ('/production/fetch_order.php') is provided either as an absolute path from the file system root directory or as a relative path from the current file (home.php).

include('production/fetch_order.php');

OR

include(dirname(__FILE__) . '/production/fetch_order.php');
rjz
  • 15,222
  • 3
  • 30
  • 33
  • Start by using `echo dirname(__FILE__);` to find out what directory `home.php` is being executed in. Confirm that `production/fetch_order.php` exists _within_ that directory. – rjz Mar 04 '12 at 19:15
  • Ok. And there's a directory in that path named `production` that contains a file called `fetch_order.php`? – rjz Mar 04 '12 at 19:17
  • Also, what error are you seeing? If none is showing, is there a chance that the file is being included but your script isn't doing anything? – rjz Mar 04 '12 at 19:18
  • The file does exist. and the errors are the warning that are being shown as mentioned in the code above. – Namit Mar 04 '12 at 19:19
  • try `echo dirname(__FILE__) . '/production/fetch_order.php';` and copy the result into a terminal to see if it gets you to the file? – rjz Mar 04 '12 at 19:21
  • However, if i paste that command into `Go to Folder`. It takes me to that file in the finder! – Namit Mar 04 '12 at 19:27
  • Is PHP executing as you or as the user for a webserver? If the server, does _it_ have permission? – rjz Mar 04 '12 at 19:30
  • I am running it on the localhost. I am able to access other php files that are at same folder level but i am unable to include any file which is in another folder from there. – Namit Mar 04 '12 at 19:31
  • There is now a troubleshooting checklist for this frequent error here : stackoverflow.com/a/36577021/2873507 – Vic Seedoubleyew Apr 12 '16 at 17:02
1

Seems that path is not correct, try:

<? include ("production/fetch_order.php"); ?>
dotoree
  • 2,935
  • 1
  • 21
  • 28