PHP Force Any File to Download In Browser Tutorial

PHP Force Any File to Download In Browser Tutorial

Listening Video

Learn to force any file to download in a browser and secure location to full path of the file.
Lesson Code
<?php
if(isset($_POST['file_name'])){
$file = $_POST['file_name'];
header('Content-type: audio/mpeg3');
    header('Content-Disposition: attachment; filename="'.$file.'"');
    readfile('mystery_folder/'.$file);
exit();
}
?>
<form action="force_download.php" method="post" name="downloadform">
  <input name="file_name" value="track1.mp3" type="hidden">
  <input type="submit" value="Download the MP3">
</form>

0 Response to "PHP Force Any File to Download In Browser Tutorial"

Post a Comment