PHP header() failing in Chrome and Firefox -


the following code works in safari not firefox or chrome

    header('content-description: file transfer');     header('content-type: application/octet-stream');     header('content-disposition: attachment; filename=' . basename($file));     header('content-transfer-encoding: binary');     header('expires: 0');     header('cache-control: must-revalidate, post-check=0, pre-check=0');     header('pragma: public');     header('content-length: ' . filesize($file));     ob_clean();     flush();     readfile($file);     ob_end_flush();     exit; 

the webpage @ xxxx might temporarily down or may have moved permanently new web address. error code: err_invalid_response

$file variable links file outside of public_html directory.

i can't seem find fix, ideas?

i've had issue filesize() on chrome , firefox in past. fix.

   <?php     function real_filesize($file) {        $fmod = filesize($file);       if ($fmod < 0) $fmod += 2.0 * (php_int_max + 1);       $i = 0;       $myfile = fopen($file, "r");       while (strlen(fread($myfile, 1)) === 1) {         fseek($myfile, php_int_max, seek_cur);         $i++;       }       fclose($myfile);       if ($i % 2 == 1) $i--;        return ((float)($i) * (php_int_max + 1)) + $fmod;      }       $filename = "somefile.ext";     $filepath = "some/dir/path/to/file/".$filename;     $filesize = real_filesize($filepath);      header('content-description: file transfer');     header('content-type: application/force-download');      header('content-type: application/octet-stream');     header("content-type: application/download");     header("content-disposition: attachment; filename=".basename($filename).";");     header('content-transfer-encoding: binary');     header('expires: 0');     header('cache-control: must-revalidate, post-check=0, pre-check=0');     header('pragma: public');     header('content-length: ' . $filesize);     ob_clean();     flush();     readfile($filepath);     exit();     ?> 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -