user3759758
user3759758

Reputation: 77

force download .zip folder using php?

I'm, trying to force download dynamic files using php.

however, the files that get downloaded are empty and it shows as 0 bytes for some reason.

I get the files name correctly and i get the force download correctly but when i download the .zip folder, it is empty and it shows as 0 bytes.

could someone please let me know whats missing from my code?

here is my code:

if (isset($_POST['id'])) {
  //echo 'correct';

  $id = $_POST['id'];
  $file = $id.'_myfiles.zip';


  header("Content-disposition: attachment; filename=$file");
  header("Content-type: application/zip");
  readfile("../upload/$file.zip");
}

Thanks in advance.

Upvotes: 1

Views: 1575

Answers (1)

andrew
andrew

Reputation: 9593

$file = $id.'_myfiles.zip'; // == "104_myFiles.zip" for example.

So change:

 readfile("../upload/$file.zip");

To:

 readfile("../upload/$file");

Upvotes: 1

Related Questions