-1

My code is:

readfile('cls_ref.csv');
fclose($fp);
$file_type   = 'octet-stream';
$file_name   = "cls_ref_" . date('m-d-Y H:i');
$file_ending = "csv";
header("Content-Type: application/$file_type; charset=utf-8");
header("Content-Disposition: attachment; filename=$file_name.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
header("Location:index.php");

I want to redirect after download to index.php but it is redirect before download.

I write a code header("Location:index.php"); at end of the file but it is redirect before download the file.

Any solution for that?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Tarun Baraiya
  • 506
  • 1
  • 9
  • 30
  • I don't think you can redirect on the PHP file where you are printing out the file. Maybe try to redirect using javascript on the page where you have the download link? Or redirect to another php page where it starts the download and redirects using the meta tag. – Khôi May 10 '12 at 07:26
  • Implement JQuery on your page. – Norse May 10 '12 at 07:33
  • possible duplicate of [PHP generate file for download then redirect](http://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect) – Andrew Marshall May 10 '12 at 07:35
  • Make link to the file open in new window and then with javascript you can redirect user with `location.href ="index.php"` – Jompper Jan 01 '14 at 15:32

1 Answers1

-3

How about a meta refresh after 10 seconds:

print "<meta http-equiv=\"refresh\" content=\"10;URL=index.php\">";
Adam
  • 1,684
  • 14
  • 18