我有一个 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;
}
}
?>
感谢帮助!