Answer the question
In order to leave comments, you need to log in
Why doesn't the file_get_contents('folder/file.json') call work?
Hello,
I have a landing page with the following structure:
index.php
|
+-assets
| +-html - тут все части лэндинга - файлы php и html (header, footer, form ...)
| | |
| | +-data - тут json файлы для загрузки данных
| | | |
| | | +-persons.json - сотрудники
| | | |
| | | +-news.json - новости
<?php
require_once '/assets/html/file.php';
?>
<?php
$url = 'data/news.json'; //путь до json файла json
$data = file_get_contents($url);
?>
$url = '../data/news.json';
$data = file_get_contents($url)
; Answer the question
In order to leave comments, you need to log in
$url = __DIR__.'/data/news.json';
$data = file_get_contents($url);
C:\OpenServer\domains\tnv4\html\top_news.php
corresponding value will be C:\OpenServer\domains\tnv4\html
Itself guessed to use an absolute path (below).
But anyway, thanks a lot for your comments!
True, now, another even more strange error has appeared:
$path_to_jsonFolder = '/var/www/.../data/www/site.ru/assets/data/';
$a = $path_to_jsonFolder . 'all-news.json';
$string = file_get_contents($a); //работает
$a = json_decode($string, TRUE);//не работает, возвращает Null.
echo $a; //Null
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question