Home  >  Article  >  PHP Framework  >  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

WBOY
WBOYforward
2023-05-26 14:49:26879browse

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);

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete