Reputation: 3225
I have mypage.php
where I try to fopen
a file, but I get:
Warning: fopen(/json/subcat/list.json): failed to open stream: No such file or directory
This is how I try to open file: $json = fopen("/json/subcat/list.json", "r");
This is the tree of project:
P.S.: I use xampp
and root
is .../htdocs/projectName/
and
list.json
contains {"list": ["a", "b"]}
, if matter.
Upvotes: 0
Views: 9193
Reputation: 428
Try this:
//your project folder:
$projectFolde = "my_project_folder";
$json = fopen($_SERVER['DOCUMENT_ROOT']."/json/subcat/list.json", "r");
Upvotes: 0
Reputation: 1304
You could use a full path using $_SERVER['DOCUMENT_ROOT']
$json = fopen($_SERVER['DOCUMENT_ROOT'] . "/json/subcat/list.json", "r");
This will give you the file path to your document root, and then will append the rest of the path onto it.
Or you relative paths, which is:
$json = fopen("json/subcat/list.json", "r");
Without the first /
Check out this link for more information about relative and absolute paths: Absolute vs. relative paths
Upvotes: 1
Reputation: 33511
You are providing a full-path:
$json = fopen("/json/subcat/list.json", "r");
and you should be providing a relative path:
$json = fopen("json/subcat/list.json", "r");
Your full path is something like /var/www/htdocs/projectName/json/subcat/list.json
.
Upvotes: 1