Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Readfile从FTP下载文件_Javascript_Php_Download_Ftp_Readfile - Fatal编程技术网

Javascript 使用Readfile从FTP下载文件

Javascript 使用Readfile从FTP下载文件,javascript,php,download,ftp,readfile,Javascript,Php,Download,Ftp,Readfile,我想让我的用户可以选择从远程FTP服务器上的唯一目录下载文件,但是其中一些文件的大小非常大。我尝试过使用,但这与大文件有关,因为我必须先将它们从远程服务器读取到本地web服务器,然后将它们保存到客户端。另一种选择是更好的选择,因为它支持分块,但是它几乎不支持浏览器 在PHP中使用可以很好地工作,在客户端将数据读入内存时,它将下载流式传输到客户端。问题是,从中提取的URL包含FTP凭据,因此我不想直接链接到它 是否有任何选项允许我为他们提供某种类型的“下载”按钮,并且仍然使用以下代码 $file_

我想让我的用户可以选择从远程FTP服务器上的唯一目录下载文件,但是其中一些文件的大小非常大。我尝试过使用,但这与大文件有关,因为我必须先将它们从远程服务器读取到本地web服务器,然后将它们保存到客户端。另一种选择是更好的选择,因为它支持分块,但是它几乎不支持浏览器

在PHP中使用可以很好地工作,在客户端将数据读入内存时,它将下载流式传输到客户端。问题是,从中提取的URL包含FTP凭据,因此我不想直接链接到它

是否有任何选项允许我为他们提供某种类型的“下载”按钮,并且仍然使用以下代码

$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);

这意味着您希望PHP从FTP读取文件并将其流式传输到您的客户端。您可以使用
phpftp
函数,也可以将文件作为输出缓冲区读取,而不是首先将其保存到PHP服务器

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
$conn_id = ftp_connect(124.23.148.103);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download file and stream it without save it on php server
if (!ftp_get($conn_id, "php://output", $server_file, FTP_BINARY)) {
    echo "There was a problem when reading file\n";
}

ftp_close($conn_id);

这意味着您希望PHP从FTP读取文件并将其流式传输到您的客户端。您可以使用
phpftp
函数,也可以将文件作为输出缓冲区读取,而不是首先将其保存到PHP服务器

header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
$conn_id = ftp_connect(124.23.148.103);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to download file and stream it without save it on php server
if (!ftp_get($conn_id, "php://output", $server_file, FTP_BINARY)) {
    echo "There was a problem when reading file\n";
}

ftp_close($conn_id);

您可以在客户端使用html
元素

<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>

您可以在客户端使用html
元素

<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>

这不是一个完美的解决方案,而是一个潜在的极其危险的解决方案@CBroe您是否建议在继续之前检查并验证每个
html
javascript
php
的文件名输入和变量?这不是一个完美的解决方案,但可能是一个极其危险的解决方案@CBroe您是否建议在继续之前检查并验证每个
html
javascript
php
的文件名输入和变量?