How to determine whether PHP is a remote file

小云云
Release: 2023-03-20 17:58:02
Original
1468 people have browsed it

This article mainly shares with you how to determine whether PHP is a remote file. I hope it can help everyone.

function chk_remote_file_exists($url) {
    $ch = curl_init(); 
    $timeout = 10; 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_HEADER, 1); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); 
    $contents = curl_exec($ch);
    if (preg_match("/404/", $contents)) {
        return false;
    }
    return true;
}
$url = 'http://www.lvxing1788.com/lvxing.html';
var_dump(chk_remote_file_exists($url));
exit;
Copy after login

Related recommendations:

PHP implements code related to downloading remote file classes

Example of how PHP determines whether local and remote files exist Analysis

PHP Download Remote File Class Sharing

The above is the detailed content of How to determine whether PHP is a remote file. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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
Popular Tutorials
More>
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!