Rectangle 27 0

content disposition PHP Force File Download Script Not working in IF statement?


if ($currentpdt<$updatedpdt) {
    echo "updatedpdt is greater than currentpdt.";
} else {
  echo "updatedpdt is not greater than currentpdt";
      require("dlfile.php"); //Now just included if the if is false
}

@user1067458 I added a little bit at the end. I assume your error reporting is hidden, otherwise you'd be seeing a headers already sent notice.

Also, if you echo something from you first file then the second file will not be able to set headers and the file's raw contents will be outputted. So you'll need to remove the echo's from your first file so that only the zip's contents gets outputted.

Thanks for the help! I added the braces to my code and it is still generating the error. Any other ideas?

Yes I understand. Just as Trott has stated. It seems you actually posted this first so I will mark your answer as correct, thank you to both of you.

Note
Rectangle 27 0

content disposition PHP Force File Download Script Not working in IF statement?


Aside from the syntax problem that others have correctly commented on, the calling file has echo() calls and the file it is including via require() has header() calls. But header() calls will not work if they follow any output to the page. So you need to get rid of those echo() calls. That may be the source of the wacky output that you're getting.

IT WORKED! Thank you so much for this solution I would have never thought of that. Will mark as correct answer in 3 minutes when I am allowed too. Thank you to all contributors.

Note
Rectangle 27 0

content disposition PHP Force File Download Script Not working in IF statement?


You have the Dangling else problem, if you don't use brackets, only the line immediately followed is considered in the else block.

Note
Rectangle 27 0

content disposition PHP Force File Download Script Not working in IF statement?


error_reporting(E_ALL);
ini_set('display_errors',1);

Well... the echos are the problems. Try adding these two lines at the start of your code, you'll see the problem:

Note