Download file from FTP using Readfile

时间:2016-12-02 05:20:41

标签: javascript php download ftp readfile

I want to give my users the option to download files from their unique directory on a remote FTP server, however some of these are incredibly large in size. I have tried using FileSaver.js but this struggles with large files as I have to read them from the remote server to the local web-server first, then save them to the client. The alternative StreamSaver.js is a better option as it supports chunking, however it has little browser support.

Using the readfile in PHP works perfectly, where it streams the download to the client as it reads the data into memory. The problem is that the URL its pulling from contains FTP credentials, thus I don't want to link directly to it.

Is there any option that would allow me to provide them with some type of a "Download" button and still make use of the following code?

$file_url = 'ftp://username:password@124.23.148.103/124.23.148.103 port 25665/server.jar';
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
readfile($file_url);

1 个答案:

答案 0 :(得分:-1)

您可以在客户端使用html angular.module('MyApp',[]) .controller('Supercntrl',function($scope){ BindYears(); function BindYears() { $scope.YearList = []; int: 1991; for (var Y = 1991; Y <= 1995; Y++) { $scope.YearList.push(Y); } } 元素

<form>

<form action="download.php">
  Username: <input type="text" name="username"><br>
  Password: <input type="password" name="password"><br>
  File name: <input type="text" name="filename"><br>
  <input type="submit" value="Download">
</form>