php to determine whether the remote image exists

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags file function image network network programming php php tutorial programming

php tutorial to determine whether the remote picture exists

function img_exits ($ url)
{
$ ch = curl_init ();
curl_setopt ($ ch, curlopt_url, $ url);
curl_setopt ($ ch, curlopt_nobody, 1); // Do not download
curl_setopt ($ ch, curlopt_failonerror, 1);
curl_setopt ($ ch, curlopt_returntransfer, 1);

if (curl_exec ($ ch)! == false)
return true;
else
return false;
}
//Method Two

function img_exists ($ url)
{
if (file_get_contents ($ url, 0, null, 0,1))
return 1;
else
return 0;
}

//

/ **
@title: How to check for the existence of a remote file (php5)
@author: axgle
@version: 1.0
* /
$ url = 'http: //www.jzread.com/';
echo url_exists ($ url);

function url_exists ($ url) {

$ head = @ get_headers ($ url);
if (is_array ($ head)) {
return true;
}
return false;

}

?>
Web effects methods

<script language = "webpage effects">
function geturl (url)
{
var xmlhttp = new activexobject ("microsoft.xmlhttp");
xmlhttp.open ("get", url, false);
xmlhttp.send ();
if (xmlhttp.readystate == 4)
alert ((xmlhttp.status == 200)? "file exists": "file does not exist");
}
</ script>
Please enter the file address: <input name = "file" id = "file" value = "http://www.jzread.com">
<button onclick = "geturl (file.value)"> test address </ button>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.