douhuanglou1445 2013-03-24 21:09
浏览 92

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>
  • 写回答

2条回答 默认 最新

  • dsaff82024 2013-03-24 21:45
    关注

    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>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题