我已经编写了PHP代码来下载我的srt文件,所以现在我需要在用户单击按钮下载以下载srt以及在srt下载后下载mkv文件时使用。使用我在此处发布的此函数,我只能下载srt,什么也没有发生,然后不下载mkv ...我在代码中两次调用了函数,但是参数不同:
download("E:\Trailers\Movie [2018].srt");
download("E:\Trailers\Movie [2018].mkv");
这是函数:
function download($file){
error_reporting(0);
set_time_limit(0);
if ($fd = fopen($file, 'r')){
$fsize = filesize($file);
$filename = explode('\\', $file);
$filename = end($filename);
$path_parts = pathinfo($filename);
$ext = strtolower($path_parts['extension']);
switch($ext){
case 'avi':
$type = 'video/x-msvideo';
break;
case 'mp4':
$type = 'video/mp4';
break;
case 'mkv':
$type = 'video/x-matroska';
break;
case 'srt':
$type = 'application/x-subrip';
break;
default:
$type='';
exit;
break;
}
header('Cache-Control: public');
header('Content-Description: File Transfer');
header('Content-Type: '.$type);
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Content-length: '.$fsize);
header('Pragma: no-cache');
$file = @fopen($file, 'rb');
if ($file){
while(!feof($file)){
print(fread($file, 1024*8));
flush();
if (connection_status() != 0){
@fclose($file);
die();
}
}
@fclose($file);
}
}
exit;
}
那么,如何下载srt以及何时下载srt以自动下载mkv?我在哪里做错了?