3

I just want to redirect the page after downloading the file, i use two methods for redirect 1- javascript 2- header but nothing works for me , my code is

<?php

$packPath = $_REQUEST['packPath'];

   header('Content-Description: File Transfer');
   header('Cache-Control: public');
   header('Content-Type: application/zip');
   header("Content-Transfer-Encoding: binary");
   header('Content-Disposition: attachment; filename='. basename($packPath));
   header("Content-Length: " .(string)(filesize($packPath)) );
   ob_clean(); #THIS!
   flush();
   readfile($packPath);

  // header('Location: ' . $_POST['accept']);
   echo '<script type="text/javascript">
          window.location.href="'.$_POST['accept'].'";
      </script>'; */
exit;
?>
Ashish-Joshi
  • 231
  • 1
  • 10
  • 1
    You should check that `$_POST` value. Right now you're vulnerable to XSS. – Ryan May 26 '14 at 04:54
  • 1
    i dont think that u can , whatever you put in the page will be added to the file that is being dowbloaded. – Exlord May 26 '14 at 04:56
  • i appreciate your reply ,but i write direct the static page url this will also not work i am getting the post value of accept on this page... so its not the error of post value of accept. you can check it with static url – Ashish-Joshi May 26 '14 at 04:56
  • Send the user to the page you want to redirect to, then from that page open an external link with the file you want to download. This can be done using javascript. – Ares May 26 '14 at 06:32
  • can you give some example of it how can it be done by javascript. – Ashish-Joshi May 26 '14 at 09:09
  • Maybe here you find the answer, http://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect/822732 , it is a similar question – jonaypelluz May 26 '14 at 09:24

0 Answers0