-1

I'm trying to create a link that will allow anyone with the link to download a file.

I'm trying this with PHP pure and CodeIgniter, but the link never gets created. I'm wondering where I should store the file, in the documents or in the database?

Thanks.

Bono
  • 4,757
  • 6
  • 48
  • 77
Stoman
  • 173
  • 1
  • 3
  • 12

1 Answers1

2

Store your file in a Server folder rather in Database. Try with below snippet to force download the file. It means, You'll get a Download dialogue window even if file formats (Like Images, PDF etc.) could be opened within the Browser.

HTML

 <a href="download.php">Download File</a>

download.php

<?php
    $yourFile = "Your_Folder/YOUR_File.ext";
    header('Content-Type: application/download');
    header('Content-Disposition: attachment; filename='.$yourFile);
    header("Content-Length: " . filesize($yourFile));

    $fp = fopen($yourFile, "r");
    fpassthru($fp);
    fclose($fp);
?>
Jenson M John
  • 5,499
  • 5
  • 30
  • 46