Hosting Solutions
mobile_logo Table of Contents

Force File Download Dialog In Browser Tutorial

Learn to force any file to download in a browser and secure location to full path of the file. <?php if(isset($_POST['file_name'])){ $file = $_POST['file_name']; // Add a file type check here for security purposes so that nobody can- // download PHP files or other sensitive files from your server by spoofing this script 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>

PHP Videos


Website Design Theme Application PHP Cookies CSS TutorialPDO Prepared Statements PHP TutorialPDO Tutorial Connect Database and Query ExampleActive Page Link Button Highlight TutorialGeoPlugin Tutorial Get User Location Information IP DetectionHashtag System and Regex PHP Programming TutorialPagination MySQLi Google Style Paged Results TutorialActive Clickable Link Function preg_replace Programming TutorialGet Favicon From Web Site Link Access External FilesRandom String Generator PHP Function Programming TutorialForce File Download Dialog In Browser TutorialCheck User Sign Up Name Ajax PHP Social Network TutorialFlat File Text Database System CMS Edit Content TutorialFlat File Text Database System Display ContentExperience Level Evaluation Programming TutorialStagger and Limit Dynamic Output in a While Loop Google AdsTwitter Dynamic Goodies Widget TutorialDynamic Google Maps Location TutorialPrepared Statements PHP mysqli Tutorial