I want to create a download button using HTML and PHP. Below is my HTML code -
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form action="download.php" method="post">
<input type="submit" name="submit" value="Download File" />
</form>
</body>
</html>
Now I have created another file, called "download.php" and kept it in the same directory as my HTML file. Code of the PHP file is given below -
<?php
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename="Sample.mp3"');
header("Content-Length: " . filesize("Sample.mp3"));
$fp = fopen("Sample.mp3", "r");
fpassthru($fp);
fclose($fp);
?>
Sample.mp3 is kept in same folder as HTML file. I got these codes from internet.
Now my problem is, when I click on download button, content of the PHP file get opened rather than downloading the file.
Can anyone please help me to fix this issue.
application/downloadshould beaudio/mpeg