Search code examples
phpimageweb-serviceshttpssubdomain

How do I read and verify if there are images that are on my PHP server but by HTTPS?


I want to check my images on my server, and I have another subdomain to save the images but they are served with HTTPS

It only works locally, but not remotely by HTTPS, as it always prints "exists directory".

$foto = "https://subdomain.example.com/images/" . $var . "/" . $var2. "/flayer";

if (file_exists($foto . ".jpg")) {
    echo "HELLO WORL";
}

if (glob($foto . ".*")) {
    if (file_exists($foto . ".jpg")) {
        $ruta = "https://subdomain.example.com/images/". $var . "/" . $var2 . "/flayer.jpg";
    }else{ 
        echo "no exists";
    }
}else{
    echo "no exists on directory";
}

Solution

  • i test with 2 options

       function remote_file_exists($url, $ext) {
        $ch = curl_init($url . $ext);
        curl_setopt($ch, CURLOPT_NOBODY, true);
        curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        if ($httpCode == 200) {
            return true;
        }
    }
    

    AND

        function remote($url, $ext) {
        if (@exif_imagetype($url . $ext)) {
            return true;
        } else {
            return false;
        }
    }
    

    Works but is so slow, something to do it more fast?