简体   繁体   中英

How to access using php a json file located in the src folder in ReactJS

How to access using php a json file located in the src folder in ReactJS

my data.json file in my Project

After building I can't access to the data.json file

The files look like this build folder

Generally speaking, you don't. The src folder contains the source code for the React app. It isn't something that should be directly used in production.

If you are using Webpack to build your production version then, as per this answer you can use the CopyWebpackPlugin plugin to copy the JSON file to your build directory and deploy it with the rest of the application.

That should give you a predictable file path (if the PHP is on the same system as the server for the React frontend) or URL (otherwise) that you can request with file_get_contents and then parse with json_decode .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM