使用PHP的file_get_contents()函数无法读取大小为8KB的json文件

时间:2016-09-16 13:05:38

标签: php json file

我正在尝试使用file_get_contents()方法读取JSON文件(大约8KB),但浏览器提示错误can't reach the site。我不认为文件大小是个问题,因为我可以使用相同的功能读取更大的(例如10KB)HTML或其他文件。我的JSON文件包含注释,我有一个函数删除所有注释,以便将有效的json提供给json_decode()。我甚至试图重命名JSON文件(目前命名为config.json),但它没有用。看起来内容是问题,但我不知道如何解决这个问题。我在Windows中使用WAMP。以下是我的浏览器显示的错误屏幕。

enter image description here

以下是要阅读的代码和var_dump() JSON:

<?php
    function clear($data) {
        return preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $data);
    }

    $data = file_get_contents('login/config.json');
    $data = clear($data);
    var_dump($data);
?>

JSON文件如下:

{
    /* 
        This is the main configuration file. Some of the below fields are optional.

        MAKE SURE THAT THIS CONFIG FILE IS OUT OF REACH OF THE OUTSIDE WORLD
    ---------------------------------------------------------------------------------
      This file will contain some sensitive data that you must not be sharing with
      others. For example: your app_secret code, database username or/and password 
      Make sure that this file is not stored in public_html or directory where
      you usually store files that your users have access to.
    ---------------------------------------------------------------------------------

    */



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        You get the app_id after creating a Facebook application.
        If not have one, visit https://developers.facebook.com/apps
        and click on the button saying 'Add a new App'
    -------------------------------------------------------------------------------
    */

    "app_id"            :       "",



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        You get an app_secret code after creating a Facebook app.
        DON'T SHARE THE app_secret with anyone. Whenever an API request call
        requires this field as a parameter, the script makes a server-to-server
        call. This field is never meant to be public.
    -------------------------------------------------------------------------------
    */

    "app_secret"        :       "",



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        This is the path to the file to which users are redirected after logging in.
        It's up to you which script do you want this field to refer to but don't
        forget to include the Verify.php class file becuase the script reffered by
        this field captures the response from login dialog and performs some actions.
    -------------------------------------------------------------------------------
    */

    "redirect_uri"      :       "",



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        This field determines what data do you want from Facebook after logging
        users in. To know more about available permissions, refer to below link
        https://developers.facebook.com/docs/facebook-login/permissions/
    -------------------------------------------------------------------------------
    */

    "scope"             :       ["public_profile", "email"],



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        This is an encrypted string unique to each login request. Options other than
        "code" are also available but "code" is best suited for calls from servers.
        https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow

        Note: Manipulations in the Verify.php file may be reuired if this field
        is manually set to value other than "code".
    -------------------------------------------------------------------------------
    */

    "response_type"     :       "code",



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        If you gonna generate a CSRF token yourself, then set this to false.
        By default, the script automatically generates one for you.
    -------------------------------------------------------------------------------
    */

    "generate_token"    :       true,



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        If you want some data to be saved in database, then set this to true and
        set up database credentials in below fields.
    -------------------------------------------------------------------------------
    */

    "save_to_db"        :       false,



    /*
    -------------------------------------------------------------------------------
        OPTIONAL
        This field is only required if "save_to_database" is set to true. If you
        want to save data in a database, type in the database name here.
    -------------------------------------------------------------------------------
    */

    "db_name"           :       "",



    /*
    -------------------------------------------------------------------------------
        OPTIONAL
        This field is only required if "save_to_database" is set to true.
        Give your database username here. 
    -------------------------------------------------------------------------------
    */

    "db_username"       :       "",



    /*
    -------------------------------------------------------------------------------
        OPTIONAL
        This field is only required if "save_to_database" is set to true.
        Give your database password here.
    -------------------------------------------------------------------------------
    */

    "db_password"       :       "",



    /*
    -------------------------------------------------------------------------------
        OPTIONAL
        This field is only required if "save_to_database" is set to true.
        Give the table name where you want to save user information.
    -------------------------------------------------------------------------------
    */

    "db_table"          :       "",



    /*
    -------------------------------------------------------------------------------
        OPTIONAL
        This field is only required if "save_to_database" is set to true.
        Populate the array with the data fields that you want to save in the database.

        fields are: user_first_name, user_last_name, user_id, user_gender, user_age,
        user_timezone, user_verified, user_friends, user_email, user_about_me,
        user_actions_books, user_actions_fitness, user_actions_music, user_actions_news,
        user_actions_video, user_birthday, user_education_history, user_events,
        user_game_activity, user_groups, user_hometown, user_likes, user_location,
        user_managed_groups, user_photos, user_posts, user_relationships, user_relationship_details,
        user_religion_politics, user_status, user_tagged_places, user_videos, user_website,
        user_work_history, user_custom_friendlists, user_insights, user_audience_network_insights,
        user_mailbox, user_page_mailboxes, user_stream, user_notifications, user_pages,

        Note: Choose what do you want to save wisely. You may never want to save a
        user's Facebook notifications.

        Note: Make sure you have given appropriate permissions (in the "scope" field)
        Without permissions, your app can't pull data from Facebook.
    -------------------------------------------------------------------------------
    */

    "db_save"           :       ["user_id", "user_first_name", "user_last_name"],



    /*
    -------------------------------------------------------------------------------
        OPTIONAL
        If this field is not set, the script will find out the version your server
        is running by manually calling some functions.
    -------------------------------------------------------------------------------
    */

    "php_version"       :       "",



    /*
    -------------------------------------------------------------------------------
        REQUIRED
        The duration (in minutes) you want the user session be saved for. When a
        user logs in, the script flags it by setting user_id as a session veriable.
        By default, this variable will only be saved for 60 minutes. That means, 
        the user will be logged in to the browser for 60 minutes if not requested to
        log out. You can extend or lower the duration of this session storage here.
    -------------------------------------------------------------------------------
    */

    "session_lifetime"  :       "60"
}

0 个答案:

没有答案