Home > PHP Framework > ThinkPHP > How to solve the problem that thinkphp saves network pictures but does not display them

How to solve the problem that thinkphp saves network pictures but does not display them

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-05-26 14:49:26
forward
1002 people have browsed it

First, check whether the saved image has been completely saved to the local hard disk. Even if the file has been saved locally, network transmission can sometimes cause the file to be corrupted invisibly. So first you need to confirm whether the file itself is intact.

Secondly, check whether the saved image is saved in the correct format. When using thinkphp to save network images, they are saved in .jpg format by default. If you want to save images in other formats, you need to make corresponding adjustments. If the format is incorrect, the saved image will not be displayed properly.

If the first two methods are not feasible, it may be because thinkphp is invalid when saving network images. At this point, you can consider using other frameworks or using native PHP implementation. The following code can easily implement the native PHP implementation of saving images

// 获取远程图片数据  
$data = file_get_contents($url);  

// 打开本地文件并写入数据  
$fp = fopen($path, 'w');  
fwrite($fp, $data);  
fclose($fp);
Copy after login

What is thinkphp

thinkphp is a free development framework that can be used to develop front-end web pages. The earliest thinkphp was developed to simplify development Generated, thinkphp also follows the Apache2 protocol. It was originally evolved from Struts. It also makes use of some good foreign framework patterns, uses an object-oriented development structure, and is compatible with many tag libraries and other patterns. It can be more convenient and faster. Developing and deploying applications, not just enterprise-level applications of course, any PHP application development can benefit from the simplicity, compatibility and speed of thinkphp.

The above is the detailed content of How to solve the problem that thinkphp saves network pictures but does not display them. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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 Issues
Why thinkphp has better performance than laravel?
From 1970-01-01 08:00:00
0
0
0
ThinkPHP Why use composer?
From 1970-01-01 08:00:00
0
0
0
thinkphp versions supported by php6
From 1970-01-01 08:00:00
0
0
0
thinkphp upload files
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template