Joe Almore Joe Almore - 1 month ago 5x
PHP Question

PHP Downloads Some Empty Files and Some Normally

I have this code to download a Zip file from the server:

$path_parts = pathinfo($_GET['a']);
$file_name = $path_parts['basename'];
$file_path = 'temp/' . $file_name;

if (file_exists($file_path)) {
$size = filesize($file_path);

header('Cache-Control: must-revalidate');
header('Pragma: public');
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file_name");
header('Expires: 0');
header("Content-Type: application/zip");
header("Content-length: $size");
header("Content-Transfer-Encoding: binary");

// read the file from disk

echo 'File does not exists';

The files are stored in a
folder and the curious thing is that if I download a
file, it downlads OK, but if the file is a
file then it downloads an empty file. Even if I change the extension of the
file to
it still downloads empty, but any other file download just fine. What could be causing this behavior?

In fact, it downloads any other file but the
files in the folder.


The problem is that PHP is not reading the ZIP files generated by the Java App that produces them. But, any other ZIP file is being read.

As I am using Java to create the ZIP files, I had to replace the method by this one posted here ( It now works normally.