Home> PHP Framework> ThinkPHP> body text

How to load images in thinkphp5

PHPz
Release: 2023-04-11 14:32:05
Original
801 people have browsed it

When developing with ThinkPHP5, loading images is a very common requirement. The following will introduce how to load images in ThinkPHP5.

  1. 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.

  1. Reference of pictures

In the template file, we can reference the picture through the following code:

picture
Copy after login

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.

  1. 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 thetag. The code is as follows:

picture
Copy after login

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.

  1. 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:

picture
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!