PHP url params并返回调用页面

My php script is supposed to download a .zip file, and increment a counter. In the code below, the parameters passed in on the URL are not being recognized, so the line to download a file doesn't do anything, and if the file download doesn't work, the count loops endlessly, incrementing the count. My provider is using PHP V5.2.

I'd like for the passed parms to work, but I can live with hardcoding "myapp.zip" in the tag.

I need to return to the page that called count.php after it's work is done.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
//$Down=$_GET['Down'];
$Down=$_Post['Down'];
echo "File:" . $Down;?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

  <meta content="en-us" http-equiv="Content-Language" />
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  <!--meta http-equiv="refresh" content="0;url=<?php echo $Down;?>"/-->
  <meta http-equiv="refresh" content="0;url=MyApp.zip"/>
</head>
<body>
  <?php
   $filePath = 'count.txt';
   // If file exists, read current count from it, otherwise, initialize it to 0
   $count = file_exists($filePath) ? file_get_contents($filePath) : 0;
   // Increment the count and overwrite the file, writing the new value<br />
   file_put_contents($filePath, ++$count);
   // Display current download count
   //echo "Downloads:" . $count;
   //header("Location: $r.htm");
?>
</body>
</html>

It's called from r.htm like this:

<form method="post" action="count.php?Down=myapp.zip" style="text-align: center">
<input type="submit" value="Download MyApp">
</form>

Here you go (tested)

Count.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php

if(isset($_POST['down'])){
$down = 'myapp.zip';
}

echo "File: <a href='$down'>$down</a>";

if(!isset($_POST['down'])){
die('NO ACCESS');

// or give them a link to go to the form and click on the button
//die('<a href="formdown.htm">Use the form to download</a>');
}

?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

  <meta content="en-us" http-equiv="Content-Language" />
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  <!--meta http-equiv="refresh" content="0;url=<?php echo $Down;?>"/-->

</head>
<body>
  <?php
   $filePath = 'count.txt';
   // If file exists, read current count from it, otherwise, initialize it to 0
   $count = file_exists($filePath) ? file_get_contents($filePath) : 0;
   // Increment the count and overwrite the file, writing the new value<br />
   file_put_contents($filePath, ++$count);
   // Display current download count
   //echo "Downloads:" . $count;
   //header("Location: $r.htm");
?>
</body>
</html>

Form:

<form method="post" action="count.php" style="text-align: center">
<input type="hidden" name="down" value="$file" />
<input type="submit" value="Download MyApp" />
</form>

This version Mike, increments the counter if the user clicks the download button, which will immediately prompt the user to save the file (somewhere on their computer).

count.php

<?php

if(isset($_POST['down'])){

$filePath = 'count.txt';
   $count = file_exists($filePath) ? file_get_contents($filePath) : 0;
   // Increment the count and overwrite the file, writing the new value<br />
   file_put_contents($filePath, ++$count);

header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=myapp.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");

readfile("myapp.zip");
}

if(!isset($_POST['down'])){
//die('NO ACCESS');

die('<a href="form.htm">Use the form to download</a>');
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>

</head>

<body>

</body>
</html>

The form:

<!DOCTYPE html>
<head>

</head>

<body>

<form method="post" action="count.php" style="text-align: center">
<input type="hidden" name="down" value="file" />
<input type="submit" value="Download MyApp" />
</form>

</body>

</html>