Home > Article > Backend Development > How to determine whether PHP is a remote file
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!