When developing with ThinkPHP5, loading images is a very common requirement. The following will introduce how to load images in ThinkPHP5.
- Static resource storage directory
First we need to determine the static resource storage directory. In ThinkPHP5, static resource files are usually stored in the public/static directory.
- Reference of pictures
In the template file, we can reference the picture through the following code:
<img src="__STATIC__/img/picture.jpg" alt="picture">
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.
- Load local images
If you need to load local images, you only need to specify the path of the image in the src attribute of the tag. The code is as follows:
<img src="/static/img/picture.jpg" alt="picture">
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.
- Load network pictures
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:
<img src="http://www.example.com/picture.jpg" alt="picture">
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!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)