0

I am downloading an asset bundle using the following code:

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

However, only some bytes get downloaded and when I open the file I get an error saying

filesize(): stat failed for ....

When I try the same code for downloading other files it works fine, but not with asset bundles.

Asset bundles are LZMA compressed by default and I think the asset bundles do not have any file extentions.

Downloading works fine when I use the following directly in the browser:

http:XXXXXXXXXX.com/AssetBundle/bundle-numb 
Bono
  • 4,757
  • 6
  • 48
  • 77
Aryaman Gupta
  • 616
  • 1
  • 8
  • 20
  • This question is not complete. Where are you downloading the file from? Are you trying to download Asset in Unity app? – Programmer Jun 25 '16 at 14:17
  • I will be but first i am checking if it is working in browser or not , and it is not. – Aryaman Gupta Jun 25 '16 at 14:34
  • What can I do to slove this problem @Programmer? – Aryaman Gupta Jun 25 '16 at 14:55
  • I can't solve your question if I don't know what your problem is. Can you explain what you are doing? I just don't get it... – Programmer Jun 25 '16 at 15:02
  • I want to simply force download an asset bundle stored in a ftp server and i have a php file named download in which the above code is present. and when i open the download.php in browser it should download the asset but instead a file get downloaded and when i open that file in notepad it show the error regarding readfile() function. – Aryaman Gupta Jun 25 '16 at 15:10
  • It is unnecessary to download it with php. Why not download it in Unity? You said you want to test if it works or not. You can test that with Unity's `WWW` class easily. – Programmer Jun 25 '16 at 15:30
  • Yes I can do that but for security reason I want to get it done with php. Here whats going to happen, I will send the platform name , asset bundle name , resolution (sd/hd) using post request and the from database I retrive the path(incomplete path) and complete the path and using that I will download the asset bundle. Also there will be a token which expire after some interval of time. – Aryaman Gupta Jun 26 '16 at 04:47

1 Answers1

0

I think i found the solution using 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;
}
?>  
Aryaman Gupta
  • 616
  • 1
  • 8
  • 20