Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单的链接提示方法';另存为';_Php_Javascript_Html_Css - Fatal编程技术网

Php 简单的链接提示方法';另存为';

Php 简单的链接提示方法';另存为';,php,javascript,html,css,Php,Javascript,Html,Css,是否有一种快速的内联方式,使我的一些链接在第一次单击后提示“将文件另存为”(与右键单击相同的屏幕)?您只需发送适当的标题即可内容配置是关键(请参阅) 请参见下面的PHP示例 /** * @author Gajus Kuizinas <g.kuizinas@anuary.com> * @copyright Anuary Ltd, http://anuary.com * @version 1.0.1 (2011 11 18) */ function ay_file_force_d

是否有一种快速的内联方式,使我的一些链接在第一次单击后提示“将文件另存为”(与右键单击相同的屏幕)?

您只需发送适当的标题即可<代码>内容配置是关键(请参阅)

请参见下面的PHP示例

/**
 * @author Gajus Kuizinas <g.kuizinas@anuary.com>
 * @copyright Anuary Ltd, http://anuary.com
 * @version 1.0.1 (2011 11 18)
 */
function ay_file_force_download($file, $file_name = NULL)
{
    if(headers_sent())
    {
        throw new Ay_Exception('Headers have been already sent. Cannot force file download.');
    }

    $file_name  = $file_name === NULL ? basename($file) : $file_name;

    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . $file_name);
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    ob_clean();
    flush();
    readfile($file);

    exit;
}
/**
*@作者Gajus Kuizinas
*@版权所有Anuary有限公司,http://anuary.com
*@version 1.0.1(2011 11 18)
*/
函数ay_file_force_download($file,$file_name=NULL)
{
如果(已发送的头)
{
抛出新的Ay_异常('标题已发送。无法强制文件下载');
}
$file\u name=$file\u name===NULL?basename($file):$file\u name;
标题(“内容描述:文件传输”);
标题(“内容类型:应用程序/八位字节流”);
标题('Content-Disposition:attachment;filename='。$file\u name);
标题(“内容传输编码:二进制”);
标题('Expires:0');
标头('Cache-Control:必须重新验证,后检查=0,前检查=0');
标题(“Pragma:public”);
标题('Content-Length:'.filesize($file));
ob_clean();
冲洗();
readfile($file);
出口
}

在php端,您真正需要的是将
内容处置
标题设置为附件,如
标题('Content-Disposition:attachment;filename=file name')。如果您必须或希望在客户端执行此操作,浏览器将自动尝试下载大量文档类型,因此您只需提供指向它的直接链接即可。显然,这种情况不会发生在您身上,所以它当然不可靠。

可能的重复并不是真正的重复,因为问题并不是直接问如何使用服务器端完成。因此,答案需要解释,它不能在客户端完成,因此需要服务器端方法。哦,但是,这不适用于我所有的链接吗?我只是想用某些链接来做这个可能的