0

我正在使用以下代码下载资产包:

<?php
$file_url = "AssetBundle/bundle-numb";
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename($file_url));
readfile($file_url);
>?

但是,只有一些字节被下载,当我打开文件时,我收到一条错误消息

filesize(): stat failed for ....

当我尝试使用相同的代码下载其他文件时,它工作正常,但不适用于资产包。

资产包默认是 LZMA 压缩的,我认为资产包没有任何文件扩展名。

当我直接在浏览器中使用以下内容时,下载工作正常:

http:XXXXXXXXXX.com/AssetBundle/bundle-numb 
4

1 回答 1

0

我想我找到了使用 php 的解决方案

<?php
$fileName = basename('bundle-rainbow');
$filePath = 'AssetBundles/'.$fileName;
if(!empty($fileName) && file_exists($filePath)){
    // Define headers
    header("Cache-Control: public");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=$fileName");
    header("Content-Type: application/zip");
    header("Content-Length:".filesize($filePath));
    header("Content-Transfer-Encoding: binary");

    // Read the file
    readfile($filePath);
    exit;
}else{
    echo 'The file does not exist.';
    echo $fileName;
}
?>  
    // Read the file
    readfile($filePath);
    exit;
}else{
    echo 'The file does not exist.';
    echo $fileName;
}
?>  
于 2016-06-27T07:27:58.377 回答