src/Converter.php
private static function validateUrl($link)
    {
        $url_parts = @parse_url($link);

        if (empty($url_parts['host'])) {
            return false;
        }
        $host = $url_parts['host'];

        if (!empty($url_parts['path'])) {
            $documentpath = $url_parts['path'];
        } else {
            $documentpath = '/';
        }

        if (!empty($url_parts['query'])) {
            $documentpath .= '?' . $url_parts['query'];
        }

        if (!empty($url_parts['port'])) {
            $port = $url_parts['port'];
        } else {
            $port = '80';
        }

        $socket = @fsockopen($host, $port, $errno, $errstr, 30);

        if (!$socket) {
            return false;
        } else {
            fwrite($socket, "HEAD " . $documentpath . " HTTP/1.0\r\nHost: $host\r\n\r\n");
            $http_response = fgets($socket, 22);

            if (preg_match('/200 OK/', $http_response, $regs)) {
                fclose($socket);
                return true;
            } else {
                return false;
            }
        }
    }
private static function validateUrl($link)
    {
        $url_parts = @parse_url($link);

        if (empty($url_parts['host'])) {
            return false;
        }
        $host = $url_parts['host'];

        if (!empty($url_parts['path'])) {
            $documentpath = $url_parts['path'];
        } else {
            $documentpath = '/';
        }

        if (!empty($url_parts['query'])) {
            $documentpath .= '?' . $url_parts['query'];
        }

        if (!empty($url_parts['port'])) {
            $port = $url_parts['port'];
        } else {
            $port = '80';
        }

        $socket = @fsockopen($host, $port, $errno, $errstr, 30);

        if (!$socket) {
            return false;
        } else {
            fwrite($socket, "HEAD " . $documentpath . " HTTP/1.0\r\nHost: $host\r\n\r\n");
            $http_response = fgets($socket, 22);

            if (preg_match('/200 OK/', $http_response, $regs)) {
                fclose($socket);
                return true;
            } else {
                return false;
            }
        }
    }
private static function validateUrl ( $ link ) { $ url_parts = @ parse_url ( $ link ) ; if ( empty ( $ url_parts [ 'host' ] ) ) { return false ; } $ host = $ url_parts [ 'host' ] ; if ( ! empty ( $ url_parts [ 'path' ] ) ) { $ documentpath = $ url_parts [ 'path' ] ; } else { $ documentpath = '/' ; } if ( ! empty ( $ url_parts [ 'query' ] ) ) { $ documentpath .= '?' . $ url_parts [ 'query' ] ; } if ( ! empty ( $ url_parts [ 'port' ] ) ) { $ port = $ url_parts [ 'port' ] ; } else { $ port = '80' ; } $ socket = @ fsockopen ( $ host , $ port , $ errno , $ errstr , 30 ) ; if ( ! $ socket ) { return false ; } else { fwrite ( $ socket , "HEAD " . $ documentpath . " HTTP/1.0\r\nHost: $host\r\n\r\n" ) ; $ http_response = fgets ( $ socket , 22 ) ; if ( preg_match ( '/200 OK/' , $ http_response , $ regs ) ) { fclose ( $ socket ) ; return true ; } else { return false ; } } }
Test whether a file exists at the given URL.

To do this as quickly as possible, we use fsockopen to just
get the HTTP headers and see if the response is "200 OK".
This is better than fopen (which would download the entire file)
and cURL (which might not be installed on all systems).

@param    string $link URL to validate
@return   boolean
@link http://www.php.net/manual/en/function.fsockopen.php#39948
Test whether a file exists at the given URL .