简体   繁体   中英

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.

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

So change:

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

To:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM