使用PHP从服务器下载MIDI文件

使用PHP从服务器下载MIDI文件,php,download,Php,Download,我有一个PHP脚本用于从服务器下载MIDI文件,下载成功,但我无法打开下载文件(我得到错误:文件格式不正确)。这是我的代码: <?php $id = $_GET["id"]; if($id == "") { print("Invalid download code!"); } else { include_once("libs/htdu_core.php"); $exec_mysql = new execute_mysql_query(); $escape_array = $exec_m

我有一个PHP脚本用于从服务器下载MIDI文件,下载成功,但我无法打开下载文件(我得到错误:文件格式不正确)。这是我的代码:

<?php
$id = $_GET["id"];
if($id == "")
{
print("Invalid download code!");
}
else
{

include_once("libs/htdu_core.php");
$exec_mysql = new execute_mysql_query();
$escape_array = $exec_mysql->escape_string(array($id));
$query = sprintf("select songpath from songs, downloads where downloadcode = '%s' and  songs.songnum = downloads.songnum",$escape_array[0]);
$path = $exec_mysql->execute($query, 1);
if($path == "")
{
print("Invalid download code!");
}
else
{
$fname = substr($path, strpos($path, '/')+1);
//$query = sprintf("update downloads set isdownload = 1 where downloadcode = '%s'",$escape_array[0]);
//$exec_mysql->execute($query, 0);
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: audio/midi");
header("Content-Disposition: attachment; filename='".$fname."'");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($path));
set_time_limit(0);
readfile($path);
exit;
}
}
?>

你能在记事本中打开下载的文件并找到一些有趣的东西吗?试着用
$fname
玩一下。尝试将扩展名.midi连接到
filename='“$fname.”“
哦,是的,我尝试用记事本打开下载的文件,我看到了来自PHP的错误消息,
set_time_limit(0);
,PHP出于安全原因禁用。我删除了它,一切正常。非常感谢!