我制作PHP代码下载功能。下载JPG文件时它正常工作,但当我使用mp3文件时,我的电脑被暂停。这是我的代码:
this is the form download.
<FORM ACTION="test.php" METHOD='POST'>
To download music1:
<INPUT TYPE="SUBMIT" VALUE="download">
</FORM>
这是下载功能。
<?php
$FileName = 'sloth.jpg'; // the name of the file that is downloaded
$FilePath = "C:\\xampp\\htdocs\\test\\sloth\\"; // the folder of the file that is downloaded , you can put the file in a folder on the server just for more order
$size = filesize($FilePath . $FileName) ;
header("Content-Type: application/force-download; name=\"". $FileName ."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ". $size ."");
header("Content-Disposition: attachment; filename=\"". $FileName ."\"");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo (readfile($FilePath . $FileName));
?>
如果我使用mp3文件,我的电脑在按下下载按钮后会暂停。