我们要处理的是判断一个远程服务器文件是否是存在,而不是自己本同服务器目录了,如果判断远程服务器的文件上否存在我们需要使用到curl_init,fsockopen,fopen方法,下面我来给大家举例说明。
fopen函数
fopen() 函数打开文件或者 URL。
如果打开失败,本函数返回 FALSE。
语法
fopen(filename)filename 规定要打开的文件或 URL。
从这个函数的说明来看是支持url的,代码如下
代码如下 | 复制代码 |
$url = 'http://www.xxx.com/images/test.jpg'; |
这样的写个人很不推荐哦,因为它这们很是浪费服务器性能资源的。
curl函数
例子
代码如下 | 复制代码 |
$url2 = 'http://www.111cn.net/ test.jpg'; $ch = curl_init(); $timeout = 10; curl_setopt ($ch, CURLOPT_URL, $url2); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $contents = curl_exec($ch); //echo $contents; if (preg_match("/404/", $contents)){ echo '文件不存在'; } ?> |
小提示,不过此函数需我服务器开启才可用哦
推荐使用此方法哦,还有一种利用fsockopen 这种是专业的远程采集版了,
代码如下 | 复制代码 |
$url = "http://www.111cn.net /.gif"; "; <br> print_r($headers); |
小提示,不过此函数需我服务器开启才可用哦

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
