2016-06-25 22 views
0

我使用下面的代碼下載一個資產包:如何強制使用php下載統一資產包?

<?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 
+0

這個問題是不完整的:當我使用直接在瀏覽器下面

下載工作正常。你從哪裏下載文件?您是否嘗試在Unity應用程序中下載資產? – Programmer

+0

我將會首先檢查它是否在瀏覽器中工作,但事實並非如此。 –

+0

如何解決此問題@Programmer? –

回答

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; 
} 
?>