English 中文(简体)
PHP 部队下载不奏效?
原标题:PHP force download not working?

在我的超文本网页上,我曾向一个应当迫使下载的网址(www.un.org/Depts)提出过JQuery ajax请求?

我的html网页(在点击事件手里连接)。

var file = "uploads/test.css";
$.ajax(
{
    type      : "POST",
    url       : "utils/Download_File.php",
    data      : {"file":file}
})

下载“File.php”的文字也一样。

<?php

Download_File::download();

class Download_File
{
    public static function download()
    {
        $file = $_POST[ file ];

        header( Content-Type: application/octet-stream );
        header( Content-Disposition: attachment );
        readfile( http://localhost/myapp/  . $file);
        exit;
    }
}
?>

But nothing is happening for some reason? I looked at the response headers in firebug and cant see any problems. Im using Xampp. Any help is much appreciated.

感谢!

问题回答

页: 1 另外,请在<条码>上注明<> 姓名/代码>。

header( Content-Type: application/octet-stream );
header( Content-Transfer-Encoding: binary );
header( Content-Disposition: attachment; filename=" .$file. " );
readfile( http://localhost/myapp/ .$file);
exit;

It s important to include double-quotes around the filename as this is required by RFC 2231. Firefox is known to have problems downloading files that have spaces in the file name if the filename is not in quotes.

另外,在您的闭幕式?>之后,确保没有白天空间。 如果在关闭的PHP标签后甚至有一间空间,则头盔被送往浏览器。

作为附带说明,如果你有几类共同档案,你将再次提出下载,那么你可以考虑具体说明这些监评类型。 这为终端用户提供了更好的经验。 例如,你可以这样做:

//Handles the MIME type of common files
$extension = explode( . , $file);
$extension = $extension[count($extension)-1];
SWITCH($extension) {
  case  dmg :
    header( Content-Type: application/octet-stream );
    break;
  case  exe :
    header( Content-Type: application/exe );
    break;
  case  pdf :
    header( Content-Type: application/pdf );
    break;
  case  sit :
    header( Content-Type: application/x-stuffit );
    break;
  case  zip :
    header( Content-Type: application/zip );
    break;
  default:
    header( Content-Type: application/force-download );
    break;
}

使用<条码>文件。

在我的经验中,麻风病造成问题(下载荷不奏效,在浏览器上打印文件内容)。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签