vendredi 30 octobre 2015

file_get_contents does not find file

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

Aucun commentaire:

Enregistrer un commentaire