How to create download link in php?

    You can create download link in many ways one of the way is as below:
    Create a file download.php like below
    <?php
      
    // The file path where the file exists
      
    $filepath = "http://mohitsharma.net/downloads/".$_GET['filename']."";
      
    header("Pragma: public");
      
    header("Expires: 0");
      
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
      
    //setting content type of page
      
    header("Content-Type: application/force-download");
      
    header("Content-Disposition: attachment; filename=".basename($filepath ));
      
    header("Content-Description: File Transfer");
      
    //Read File it will start downloading
      
    @readfile($filepath);
     
     
    ?>
    Use following link to download
    <a href="http://mohitsharma.net/download.php?filename=test.doc">Download</a>
    5
    Average: 5 (1 vote)