标签: force-download

强制下载,来自php文件

我正在尝试下载.mp4文件.(约1.3GB大小).我正在使用以下内容:

<?php 
$path = "video.mp4";
header('Accept-Ranges: bytes');  // For download resume
header('Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header('Content-Description: File Transfer' );
header('Content-Disposition: attachment; filename="'.basename( $path ).'"' );
header('Content-Length: ' . filesize($path));  // File size
header('Content-Transfer-Encoding: binary');  // For Gecko browsers mainly
header('Content-Type: application/octet-stream' );
header('Expires: 0' );
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Pragma: no-cache' );
ob_clean();
flush();
readfile($path);
Run Code Online (Sandbox Code Playgroud)

我打开我的php文件,firefox弹出"想要保存"菜单.尺寸看起来正确.我按"另存为",到我的桌面.最终下载的文件,以随机大小列出,大约400MB(330,463和440).

响应标题是:

Connection: Keep-Alive
Content-Disposition:    attachment; filename="//www.frederikspang.dk/elevgallavideo.mp4"
Content-Length: 1422778850
Content-Type:   video/mp4
Date:   Sun, 30 Jun 2013 …
Run Code Online (Sandbox Code Playgroud)

php http-headers force-download

5
推荐指数
1
解决办法
5844
查看次数

使用瑞典字符 (åäö) 文件名强制下载

我使用以下代码和函数来强制下载文件,如果文件名不包含瑞典语字符,则效果很好\xc3\x85 \xc3\x84 \xc3\x96.

\n\n
$file_id = $_GET[\'f\'];\n\n$sql =  " SELECT * ".\n            " FROM attachment ".\n            " WHERE attachment_id = ".$file_id." ".\n\n            $res = mysql_query($sql);\n            $row = mysql_fetch_array($res);\n            $filename = $row[\'filename\'];\n            $USER_ID = $row[\'user_id\'];\n            $Directory_id = $row[\'directory_id\'];\n            $target_path = "upload/".$USER_ID."/".$Directory_id."/";\n\n\nfunction Download($path, $speed = null)\n{\n    if (is_file($path) === true)\n    {\n        $file = @fopen($path, \'rb\');\n        $speed = (isset($speed) === true) ? round($speed * 1024) : 524288;\n\n        if (is_resource($file) === true)\n        {\n            set_time_limit(0);\n            ignore_user_abort(false);\n\n            while (ob_get_level() > 0)\n            {\n                ob_end_clean();\n            }\n\n …
Run Code Online (Sandbox Code Playgroud)

php special-characters force-download

5
推荐指数
1
解决办法
1955
查看次数

php强制下载在屏幕上显示垃圾

我正在尝试从Ubuntu的/ tmp文件夹下载一个zip文件。但是,当我运行Php代码时,它在浏览器上显示垃圾文本,而不是显示下载框。我尝试了一个简单的文本文件,没有显示下载对话框,而是在浏览器中打印了内容。为什么此强制下载无法正常工作。下面是代码。

if (file_exists($dir.$filename)) {
            header("Content-type: application/force-download");
            header("Content-Transfer-Encoding: Binary");
            header("Content-length: ".filesize($dir.$filename));
            header('Content-disposition: attachment; filename='.basename($dir.$filename));
            readfile($dir.$filename);
            exit(0);
        }

    `    
Run Code Online (Sandbox Code Playgroud)

php zip force-download

2
推荐指数
1
解决办法
1687
查看次数

强制从 wordpress 中的 URL 下载 PDF 文件

在 WordPress 中,如何创建指向“file.pdf”等文件的链接并强制下载而不是在浏览器中打开文件?

pdf wordpress force-download

2
推荐指数
2
解决办法
1万
查看次数

Php force下载 - 下载损坏的文件

嗨,我试图允许下载与产品相关的演示文件.我的代码是这样的

if(isset($_POST['submit'])){     
    $root = $_SERVER['DOCUMENT_ROOT'];
    $path = "/download/";
    $path = $root.$path;
$filename = $demo;
$file = $path.$filename;
header('Content-Type: application/force-download');
header("Content-Transfer-Encoding: Binary"); 
header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
header("Content-Length: ".filesize($file));
 readfile($file);
    }
Run Code Online (Sandbox Code Playgroud)

我能够获得与产品相关的文件名

$演示

用户提交信息后,将自动开始下载.现在,这是使用正确的文件名下载不存在的文件或损坏的文件.请帮忙

php force-download

1
推荐指数
1
解决办法
1009
查看次数

PHP强制下载带有空格的文件名

好的,让脚本下载具有正确文件名的文件似乎有点麻烦。

如果我删除像这样的空格和破折号

if($type == 'mc'){
    $file_name = $_POST['Ids'];
    $file_name = str_replace('-', '', $file_name);
    $file_name = str_replace(' ', '&amp;', $file_name);
    $url = base64_decode($stream);
    $file_url = "scd.php?stream=".$url."&name=".$file_name."";
    $url = array('url' => $file_url);
    echo json_encode($url);
}
Run Code Online (Sandbox Code Playgroud)

这是 scd.php

<?php
$file = $_GET['stream'];
$name = $_GET['name'];
header("Content-type: application/x-file-to-save");
header("Content-Disposition: attachment; filename=".$name.".mp3");
readfile($file);
exit();
?>
Run Code Online (Sandbox Code Playgroud)

它将强制下载,但只会将第一个单词保存在发送的名称中。所以说这个名字是Your Song Here要保存为,Your.mp3但是如果我str_replace$file_name变量中删除,那么它将尝试将文件保存为Your不带扩展名,但仍然只是第一个单词。

我需要它来传递整个$file_name变量ex。Your Song Here.mp3并将其另存为MP3文件。

我不太确定自己在做什么错

php force-download

1
推荐指数
1
解决办法
2140
查看次数

使用Spring MVC和自我实现的拦截器强制下载文件会产生一个奇怪的问题

我的所有控制器都扩展了以下抽象类:

public abstract class AbstractController {

    public HttpServletRequest request;
    public HttpServletResponse response;
    public ModelMap model;

}
Run Code Online (Sandbox Code Playgroud)

而且,我实现了以下拦截器:

public class HttpRequestInterceptor implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException {
        if (handler instanceof AbstractController) {
            AbstractController controller = (AbstractController) handler;
            controller.request = request;
            controller.response = response;
            controller.model = new ModelMap();
        }
        return true;
    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) {
        if (handler instanceof AbstractController && modelAndView != null) {
            AbstractController controller …
Run Code Online (Sandbox Code Playgroud)

java spring-mvc httpresponse interceptor force-download

0
推荐指数
1
解决办法
4644
查看次数