关于批量下载ftp服务器的文件的方法
前言:批量下载网上有一堆,但是无奈都基本是对自己项目作用不大,研究了一下,分享和记录
1.首先要知道这个是从html页面发起的所以必须要加入这段话才行
//之前尝试用ajax和layer弹层来实现发现都会产生错误因此必须要用这个方法才行,前端的方法
location.href = 你想要访问的.php网页;
//后端的实现方法
<?php
//这个class类是借鉴网友的,具体内部逻辑我也不太清晰,所以。。。。。。。
class zipfile {
var $datasec = array ();
var $ctrl_dir = array ();
var $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
var $old_offset = 0;
function unix2_dostime($unixtime = 0){
$timearray = ($unixtime == 0) ? getdate () : getdate($unixtime);
if ($timearray ['year'] < 1980){
$timearray ['year'] = 1980;
$timearray ['mon'] = 1;
$timearray ['mday'] = 1;
$timearray ['hours'] = 0;
$timearray ['minutes'] = 0;
$timearray ['seconds'] = 0;
}
return (($timearray ['year'] - 1980) << 25) | ($timearray ['mon'] << 21) | ($timearray ['mday'] << 16) | ($timearray ['hours'] << 11) | ($timearray ['minutes'] << 5) | ($timearray ['seconds'] >> 1);
}
function add_file($data, $name, $time = 0){
$name = str_replace('\\', '/', $name);
$dtime = dechex($this->unix2_dostime($time));
$hexdtime = '\x' . $dtime [6] . $dtime [7] . '\x' . $dtime [4] . $dtime [5] . '\x' . $dtime [2] . $dtime [3] . '\x' . $dtime [0] . $dtime [1];
eval('$hexdtime = "' . $hexdtime . '";');