There's a file on a server. The file is a ZIP file.
The file has to be downloaded through my server to the client.
I tried using the readfile function but instead of downloading a file it just displays wierd symbols...
I uploaded it here: http://b-games.co.il/test/download/
This is the code:
$file = "2title3.gif";
if(file_exists($file))
{
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');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
I also tried using this:
$url = 'http://example.com/some.url';
$src = fopen($url, 'r');
$dest = fopen('php://output', 'w');
$bytesCopied = stream_copy_to_stream($src, $dest);
But it did the same thing... Just displayd wierd symbols.
What am I doing wrong? http://php.net/manual/en/function.readfile.php Here it says it should work...
An important update:
On my localhost the same code works!
Anyone knows why?
Thanks!