php实现从ftp服务器下上载文件 怎么实现自动上载不弹出文件上载框?上载的文件却比原文件小一些

WBOY
Release: 2016-06-13 13:24:24
Original
1055 people have browsed it

php实现从ftp服务器上下载文件 如何实现自动下载不弹出文件下载框?下载的文件却比原文件小一些?
$filename="/www/767675.dat";
php_ftp_download($filename);
 
function php_ftp_download($filename) {
  
 $phpftp_host = "ftplocalhost";  // 服务器地址
 $phpftp_port = 21;      // 服务器端口
 $phpftp_user = "name";    // 用户名
 $phpftp_passwd = "passwrd";    // 口令
  $ftp_path = dirname($filename) . "/";// 获取路径
  $select_file = basename($filename);// 获取文件名
  $ftp = ftp_connect($phpftp_host,$phpftp_port);// 连接ftp服务器
  if($ftp)
  {
  if(ftp_login($ftp, $phpftp_user, $phpftp_passwd)) { // 登录
  if(@ftp_chdir($ftp,$ftp_path)) {// 进入指定路径
  $tmpfile = tempnam( getcwd()."/", "temp" ); // 创建唯一的临时文件
  if(ftp_get($ftp, $tmpfile, $select_file, FTP_BINARY)) { // 下载指定的文件到临时文件
  ftp_quit( $ftp ); // 关闭连接
  header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=" . $select_file);
     readfile($tmpfile);
     unlink($tmpfile );// 删除临时文件
  exit;
}
    unlink($tmpfile );
  }
  }
 }
 ftp_quit($ftp);
}
?>

1.php实现从ftp服务器上下载文件 如何实现自动下载不弹出文件下载框?不提示下面这个下载选择框。
2、怎么下载保存的文件提示下载成功,下载的文件却比原文件小一些?

------解决方案--------------------
以我的观点这个下载提示应该不会消失,因为这个是windows对于系统安全做的一个防护措施,如果你点击一个文件就自动下载到本地,那么岂不是电脑很不安全?

你下载的文件是在两个不同的系统平台么?如果是,那么会造成不同大小。也有可能数据读取不完整,你可以自己FTP下载试试,是否文件一样。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!