current position:Home>How to download files to browser through PHP FTP

How to download files to browser through PHP FTP

2022-02-02 21:44:47 CSDN Q & A

I'm developing an online file management feature , I hope users can pass php Download remote FTP The file of
Use HTML Of A Label matching download Use can meet some requirements , However, when a file can be opened directly by the browser, he will open it and download the opened code , Not the source code ( for example : There is a in my remote service index.php file , I want to download him My initial idea was that the file management system would download remote files to a local directory , The front-end allows users to jump to this directory and directly obtain This method ZIP Etc format is feasible, but encountered php html txt When the browser can be opened directly, it cannot be downloaded directly, or the downloaded file is the file after the code runs )


Refer to the answer 1:
<?php$a="test.php";// file name $b=fopen($a,"rb");Header("content-type:application/octet-stream");Header("accect-ranges-bytes");Header("accect-length:".filesize($a));Header("content-disposition:attachment;filename=".$a);echo fread($a,filesize($a));fclose ($a);exit();?>

Try this.

Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.

Random recommended