The FTP server stores files from 0.1 to 300 mb.

It is necessary that users can download these files from the site from the browser.

Now the function responsible for issuing files looks like this:

public function save($path, $filename = null) { if(empty($filename)) { $filename = basename ( $path ); $file = $path; } else { $file = $path . '/' . $filename; } ob_start(); $result = @ftp_get($this->_conn_id, "php://output", $file, FTP_BINARY); $data = ob_get_contents(); $datasize = ob_get_length(); ob_end_clean(); if ($result) { $f = ['data' => $data, 'size' => $datasize]; ftp_close($this->_conn_id); if (!$f) { error("Error. File ".$file." not found.", true); } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . $filename); 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: ' . $f['size']); echo $f['data']; exit(); } else { error("Error!!!! File ".$file." not found.", true); } return null; } 

But she has a problem: the file is first downloaded completely from FTP to a server with PHP, and then sent to the user for output. For small files, this is not fatal, but for large files - you have to wait for minutes until the "Save file as ..." window comes up in the browser.

What can be done to speed up or optimize this process? How can I split a file into parts or something else ...? Because downloading files of 300 MB each time on php server is somehow fat.

  • And to give ready for downloading the file, by reference, in any way what? - And
  • ftp serv remote. 8-10 gigov of files are collected for each month, - there is no need to store all this on the server with the application. The application just reads the ftp directories, creates links for downloading files and gives them to the user - Anton
  • Some dubious idea to give via php. It is better to do this through a web server, nginx desirable through an XSendfile . Although apache , there is also a mod_xsendfile . - And
  • I do not see how this can be linked to a remote ftp-server. In addition, access to it by IP - just two machines. On one - only ftp serv, on the second - only our application. Those. It does not work out just like that " login: password @ host / file ". I understand that making "how to download a file with FTP" is at least 100,500. But there is only the problem of one module, nobody will be able to shovel the whole application. Need to download via PHP - Anton

0