Home  >  Article  >  Backend Development  >  How to determine whether PHP is a remote file

How to determine whether PHP is a remote file

小云云
小云云Original
2018-03-03 15:02:251482browse

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;

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!

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