PHP Force下载不适用于ZIP文件

时间:2019-06-27 04:52:06

标签: php

我正在尝试使用$filepath='http://localhost/mb/inc/tmp/liberty/xml_invoice.zip' header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="test.zip'); 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($filepath)); ob_clean(); flush(); readfile($filepath); exit(); 下载一个zip文件。但是它返回一些特殊字符。

我尝试了以下代码。

�Q�s�+k�X�ߡB�R�EE����m��@;Ok����A���R�2vZ�j�F�Mo� C�

当我运行这段代码时,我得到的输出像一些特殊字符一样。

{{1}}

2 个答案:

答案 0 :(得分:0)

如果要传递ZIP文件,则还需要使用正确的MIME内容类型!

def solve(n):
    l=range(1,n+1)
    length = n
    items=l
    def inner(ix=[]):
        do_yield = len(ix) == length - 1
        for i in range(0, length):
            if i in ix: #avoid duplicates
                continue
            if do_yield:
                yield tuple([items[y] for y in ix + [i]])
            else:
                for p in inner(ix + [i]):
                    yield p
    t=inner()
        #rr=list(pp(list(range(1,n+1)),4))
    #l=''.join(l)
    #=list(l)
    #t=pp(list(l))
    #print(t)
    result=0
    for j in list(t):
        #print("j",j)
        if j[0]<j[1] and j[1]<j[2] and j[2]<j[3]:
                #result=j[0]
                #for k in j[1:]:
                    #result=self.gcd(result,k)
            result=result+1
                #su=su+self.fast(result,4)
    print(result%1000000007)
#ob=Solution()
for i in range(int(input())):
    n=input()
    n=int(n)
    solve(n)

答案 1 :(得分:0)

尝试一下:提供zip文件的路径。

$filepath = "/path/to/some_file.zip";
 $file_name = basename($filepath);
 header("Content-Type: application/zip");
 header("Content-Disposition: attachment; filename=$file_name");
 header("Content-Length: " . filesize($filepath));
 readfile($filepath);
 exit;