file_get_contents does not find file

时间:2015-10-30 23:24:16

标签: php json file path file-get-contents

The following code tries to load the file content into a string. // Loads the forecast from json public function loadForecast() { try { $filename = "../../forecast/forecast.json"; echo "Dateiname: '" . $filename . "'\n"; echo "Pfad: '" . realpath($filename) . "'\n"; if ($forecastContent = file_get_contents($filename) !== false) { echo "got content"; } else { echo "no content"; } } catch (Exception $e) { echo "Caught exception: " . $e->getMessage(); } } Can anybody tell me my fault? I'm always getting "no content". realpath does print "" (empty string). My Webspace hierachie is / Backend my PHP file forecast forecast.json

2 个答案:

答案 0 :(得分:3)

You have too many ../ in the path. You only need to go up 1 level to get to the common ancestor of the Backend directory and the file. So it should be ../forecast/forecast.json

答案 1 :(得分:1)

我必须使用./而不是../: - )

相关问题