duanjiyun7391 2014-01-29 19:48
浏览 37

$ _POST变量在没有HTML标头的页面上不可用

I used to be able to post variables to pure PHP pages, but it seems to have been broken by a server setting change with our web host, because this used to work just fine. Basically, I've set up a form to retrieve and allow the user to download a file from a secure location outside of the public folder on the server (only to authorized users). It works like this:

request_file.php

<?php
session_start();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Request File</title>
</head>

<body>

<form name="request_file" method="post" action="retrieve_file.php" enctype="multipart/form-data">
<input type="text" name="filename" />
<input type="submit" value="Submit" />
</form>

</body>
</html>

retrieve_file.php

<?php
session_start();
header("Vary: User-Agent");
header("Pragma: public");
header("Content-type: text/plain");
header("Content-Disposition: attachment; filename=".$_POST['filename']);

readfile( "../../".$_SESSION['userid']."/".$_POST['filename'] );

?>

However, if I replace the retrieve_file.php code with simply this:

<?php
echo "<pre>";
var_dump( $_POST );
echo "</pre>";
?>

It will print out an empty array, every time. However, if I put HTML headers on retrieve_file.php, it works just fine. However, for exporting a file, this won't really work since the headers have to be sent out AFTER the page gets its post variables.

Any ideas how to work around this? Please don't berate me for pulling files this way, it actually works well for our very specific application.

Thanks!

Additional Information

PHP Version: 5.4

  • 写回答

1条回答 默认 最新

  • doule0941 2014-01-29 19:56
    关注

    You need to access with the $_FILES variable, like this:

    $_FILES["file"]["filename"]

    Check more at http://www.w3schools.com/php/php_file_upload.asp

    评论

报告相同问题?

悬赏问题

  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab