ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
【ASP&PHP】 Excelを開かずにダウンロードする ( No.0 )
日時: 2009/02/22 00:33
名前: lightbox





呼び出し : excel.asp?fname=format_00_week_report

<%
Response.ContentType = "application/vnd.ms-excel"
Response.Addheader "Content-Disposition", "attachment; filename=" & Request.QueryString("fname") & ".xls"
Response.ExpiresAbsolute=#May 31,2000 23:59:59#

Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Open
Stream.Type = 1	' StreamTypeEnum の adTypeBinary
Stream.LoadFromFile Server.MapPath( Request.QueryString("fname") & ".xls" )
Response.BinaryWrite Stream.Read
Stream.Close
Set Stream = Nothing
%>
以下 HTTPヘッダ
HTTP/1.1 200 OK
Date: Thu, 08 Mar 2007 12:51:51 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
MicrosoftOfficeWebServer: 5.0_Pub
Content-Disposition: attachment; filename=format_00_week_report.xls
Content-Length: 32256
Content-Type: application/vnd.ms-excel
Expires: Wed, 31 May 2000 14:59:58 GMT
Cache-control: private
↓PHP
<?
header( "Content-Type: application/vnd.ms-excel" );
header( "Content-Disposition: " . "attachment; filename=" . $_GET["fname"] . ".xls" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );

$data = @file_get_contents( $_GET["fname"] . ".xls" );
print $data;
?>