When developing with ThinkPHP5, loading images is a very common requirement. The following will introduce how to load images in ThinkPHP5.
First we need to determine the static resource storage directory. In ThinkPHP5, static resource files are usually stored in the public/static directory.
In the template file, we can reference the picture through the following code:
In the above code, __STATIC__ represents Is the absolute path to the public/static directory. Therefore, any file in the public/static directory can be referenced in this way. The images are placed in the public/static/img directory. Just replace img with the name of the folder, such as public/static/css, public/static/js, etc.
If you need to load local images, you only need to specify the path of the image in the src attribute of thetag. The code is as follows:
It should be noted that the path here is relative to the root path of the domain name, not the path relative to the application root directory. For example, if the application is deployed under the domain name myapp.com, then "/" represents the root path of the domain name myapp.com.
If you need to load pictures on the network, you only need to specify the URL address of the picture. The code is as follows:
Here The path is the complete URL address where the image is located.
In general, loading images in ThinkPHP5 is very convenient. You only need to put the image in the correct location and then make the correct reference in the code. Hope this article is helpful to you.
The above is the detailed content of How to load images in thinkphp5. For more information, please follow other related articles on the PHP Chinese website!