我对HTML有一个基本的概念。我想在我的样本网站创建下载链接,但我不知道如何创建它。我如何制作一个下载文件的链接而不是访问它?


当前回答

在支持HTML5的现代浏览器中,可以实现以下功能:

<a href="link/to/your/download/file" download>Download link</a>

你也可以用这个:

<a href="link/to/your/download/file" download="filename">Download link</a>

这将允许您更改实际正在下载的文件的名称。

其他回答

下载属性是HTML5中<a>标签的新属性

<a href="http://www.odin.com/form.pdf" download>下载表单</a> 或 <a href="http://www.odin.com/form.pdf" download="Form">下载表单</a> .

我更喜欢第一个,它在任何扩展方面都是可取的。

下载链接是指向您想要下载的资源的链接。它的构造方式与其他链接相同:

<a href="path to resource.name of file">Link</a>

<a href="files/installer.exe">Link to installer</a>

像这样

<a href="www.yoursite.com/theThingYouWantToDownload">Link name</a>

因此,example.com网站上的文件名。jpg将如下所示

<a href="www.example.com/name.jpg">Image</a>

在支持HTML5的现代浏览器中,可以实现以下功能:

<a href="link/to/your/download/file" download>Download link</a>

你也可以用这个:

<a href="link/to/your/download/file" download="filename">Download link</a>

这将允许您更改实际正在下载的文件的名称。

我知道我迟到了,但这是我搜索1小时后得到的

 <?php 
      $file = 'file.pdf';

    if (! file) {
        die('file not found'); //Or do something 
    } else {
       if(isset($_GET['file'])){  
        // Set headers
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        header("Content-Disposition: attachment; filename=$file");
        header("Content-Type: application/zip");
        header("Content-Transfer-Encoding: binary");
        // Read the file from disk
        readfile($file); }
    }

    ?>

对于可下载链接,我是这样做的

<a href="index.php?file=file.pdf">Download PDF</a>