Question: ### Update

Just found out from my error logs `readfile() has been disabled for security reasons` Any alternatives instead of `readfile()`? Will `fopen` or `fread` work with zip files?

==================================================================================

My script:

```
<?php

$str = "some blah blah blah blah";
file_put_contents('abc.txt', $str); // file is being created
create_zip(array('abc.txt'), 'abc.zip'); // zip file is also being created

// now creating headers for downloading that zip

header("Content-Disposition: attachment; filename=abc.zip");
header("Content-type: application/octet-stream; charset=UTF-8");    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header('Content-Transfer-Encoding: binary'); // added this line as per suggestion
header('Content-Length: ' . filesize("abc.zip")); // added this line as per suggestion
readfile("abc.zip");
//echo 'do something'; // just for testing purpose to see if code is running till the end
exit;

```

When I run the above script, I get a blank page (No download prompt). When I uncomment the "do something" line, I get that on the screen. So the script is running till the last line.

I also put `error_reporting(E_ALL)` at the top of the page but nothing is showing up.

What am I missing here?

Answer: 
Try adding `Content-Length` headers.
See [PHP readfile()](http://php.net/manual/en/function.readfile.php) documentation for a full example.
One alternative to `readfile()` would be to `echo` the link to the **ZIP** file itself where people can simply click on it and will then be prompted to save the file.

Using: `echo "<a href='$filename'>File download</a>";`

PHP
---

```
<?php
$str = 'some blah blah blah blah';
$zip = new ZipArchive();
$filename = "abc.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)==TRUE) {
$zip->addFromString("abc.txt", $str);
$zip->close();
}

echo "<a href='$filename'>File download</a>";
exit();
?>

```

This is usually the way to ZIP a file then open up a prompt to `save file as...`

```
<?php
ob_start();
$str = 'some blah blah blah blah';

$zip = new ZipArchive();
$filename = "abc.zip";

if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
   exit("cannot open <$filename>\n");
}

$zip->addFromString("abc.txt", $str);
$zip->close();

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Content-Transfer-Encoding: binary");

clearstatcache();
header("Content-Length: ".filesize('abc.zip'));

ob_flush();
readfile('abc.zip');
?>

```