0

I'm trying to get a zip file to automatically download:

            $attachment_location =  "https://dev.com/daily/updates/com_prog_v1_8_0.zip";

            if (file_exists($attachment_location)) {

                header($_SERVER["SERVER_PROTOCOL"] . " 200 OK");
                header("Cache-Control: public"); // needed for internet explorer
                header("Content-Type: application/zip");
                header("Content-Transfer-Encoding: Binary");
                header("Content-Length:".filesize($attachment_location));
                header("Content-Disposition: attachment; filename=com_prog_v1_8_0.zip");
                readfile($attachment_location);
                die(); 

            }

I've tried to link in the browser and the file downloads without a problem. I'm not sure what to do to debug it. As far as I can tell it is right. I'm expecting to run this file (and index.php file) and have it kick off the download of the file. I've had a good look at the other posts and can't figure out the problem.

I've also tried just

            file_put_contents("com_prog_v1_8_0.zip", fopen("https://dev.com/daily/updates/com_prog_v1_8_0.zip", 'r'));

but that also throws

Error: File not found.

Any ideas what I can do to track down the problem would be great. I'm sure it must be something I can't see for looking!

thansk

user1616338
  • 557
  • 1
  • 8
  • 24

1 Answers1

0

I dont believe file_exist() works with urls. Try something like this instead:

function url_exists($url){
    $ccmd = curl_init($url);    
    curl_setopt($ccmd, CURLOPT_NOBODY, true);
    curl_exec($ccmd);
    $rtncode = curl_getinfo($ccmd, CURLINFO_HTTP_CODE);
    curl_close($ccmd);

    if($rtncode == 200){
       return true;
    }
    return false;  
}
R. Smith
  • 551
  • 4
  • 10