How can one check to see if a remote file exists using PHP?

前端 未结 22 2602
死守一世寂寞
死守一世寂寞 2020-11-22 05:52

The best I could find, an if fclose fopen type thing, makes the page load really slowly.

Basically what I\'m trying to do is

22条回答
  •  别那么骄傲
    2020-11-22 06:28

    There's an even more sophisticated alternative. You can do the checking all client-side using a JQuery trick.

    $('a[href^="http://"]').filter(function(){
         return this.hostname && this.hostname !== location.hostname;
    }).each(function() {
        var link = jQuery(this);
        var faviconURL =
          link.attr('href').replace(/^(http:\/\/[^\/]+).*$/, '$1')+'/favicon.ico';
        var faviconIMG = jQuery('')['appendTo'](link);
        var extImg = new Image();
        extImg.src = faviconURL;
        if (extImg.complete)
          faviconIMG.attr('src', faviconURL);
        else
          extImg.onload = function() { faviconIMG.attr('src', faviconURL); };
    });
    

    From http://snipplr.com/view/18782/add-a-favicon-near-external-links-with-jquery/ (the original blog is presently down)

提交回复
热议问题