一个名为“transfer.php”的文件应该提供一个文件供下载。它提供了一个与原始文件大小相同的“.php”文件,而不是下载文件。我是不是把标题弄错了?
谢谢!
<?php
session_start();
$path = $_SESSION['myvar'];
$mm_type = "application/octet-stream";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: ".$mm_type);
header("Content-Length: ".(string)(filesize($path)) );
header("Content-Disposition: attachment; filename=".basename($path).'"');
header("Content-Transfer-Encoding: binary\n");
readfile($path); // outputs the content of the file
exit();