Home  >  Article  >  Backend Development  >  PHP determines whether the remote image can be called

PHP determines whether the remote image can be called

php中世界最好的语言
php中世界最好的语言Original
2018-05-21 11:16:202117browse

This time I will bring you PHP to determine whether a remote image can be called. What are the precautions for PHP to determine whether a remote image can be called? The following is a practical case, let's take a look. Note: When making a picture preview, I encountered a problem, which is to determine whether the

remote file

exists (not the same server). Examples, multiple methods to determine whether remote images exist.


Code description:

Method one, returns FALSE regardless of whether the picture is present;

Method two, feasible under windows, returns TRUE regardless of whether the picture is present under LINUX;
Method 3 should be the most appropriate
In addition: There are efficiency issues with the get_headers() method, and it is recommended not to use it as this solution.

fsockopen version:

";
    print_r($headers);

Use

http status code

to determine whether the file exists. For example, responses 302, 301, 404, etc. all mean that it does not exist. If it is 200, 304, etc., it can Treat the file as existing. 1, fopen() method:


2, CURL method:

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related matters on the php Chinese website article!

Recommended reading:

php array function shuffle() and array_rand() random function usage steps detailed explanation

php array search function usage Summary of methods

The above is the detailed content of PHP determines whether the remote image can be called. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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