Php 单击“下载”按钮后,计算机将被挂起
我做php代码下载功能。下载JPG文件时它正常工作,但当我使用mp3文件时,我的电脑会被挂起。这是我的密码:Php 单击“下载”按钮后,计算机将被挂起,php,download,Php,Download,我做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';
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文件,单击“下载”按钮后,我的计算机将被挂起。您的意思是,如果用户选择mp3文件,当脚本需要JPEG时,会发生错误。那么您是在试图强制文件上载类型为JPEG?或者是否允许用户选择JPEG或MP3?我将用MP3文件替换jpg文件。当我点击下载按钮时,我的电脑突然被暂停。我的意思是将$FileName='sloth.jpg'替换为$FileName='music.mp3'。mp3文件已经在下载目录中。