【发布时间】:2014-03-16 23:17:02
【问题描述】:
我只是玩了一会儿,我正在使用 php 强制将文件从我的数据库下载到 ole'desktop,下载部分很好,然后当我打开文件时(如果在查看器中它是jpg)应用程序告诉我文件已损坏
这是html
<form action="view_file.php" method="post" name="downloadform">
<input name="file_name" type="hidden" value=<?php echo $row['file_path'];?>>
<input name="file_type" type="hidden" value=<?php echo $row['file_type'];?>>
<button type="submit" value="Secure Download" class="col-xs-12 col-sm-4 col-md-4 col-lg-4 btn btn-default pull-left view_file"><span class="glyphicon glyphicon-cloud-download"></span> Secure Download</button>
</form>
这是我的 php sn-p //清理输出缓冲区 ob_clean();
//If statement gets everything started
if(isset($_POST['file_name'])){
//Grab global variables from the HTML form
$file = $_POST['file_name'];
$file_type2 = $_POST['file_type'];
//Grab last item in array then explode to only grab the file name
$filename = array_pop(explode('/', $file));
//Grab file type from global variables in HTML form
header("Content-type: ".$file_type2."");
////Grab file path from global variables in HTML form
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($file);
exit();
}
有什么建议吗??
【问题讨论】:
-
用文本编辑器打开文件,检查顶部是否有php错误或html
-
我发现的错误是 Strict Standards: Only variables should be passed by reference in
-
你应该检查请求的是什么文件,否则可以下载任何文件。
标签: php http-headers