Rumah > php教程 > php手册 > web下载网站代码

web下载网站代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Lepaskan: 2016-06-06 19:32:27
asal
1675 orang telah melayarinya

1.打包代码,并直接通过浏览器下载 2.解压zip文件到服务器 PHP ?php/** * @author MarkZhao(zhaody901#126.com) */$dir = dirname(__FILE__).'/';// zip and download// zip.php?type=zipdir=subdir// unzip deflate way zipped zip file// zip.php?type=unzip

1. 打包代码, 并直接通过浏览器下载
2. 解压zip文件到服务器
PHP
<?php
/**
 * @author MarkZhao(zhaody901#126.com)
 */
$dir = dirname(__FILE__).'/';
// zip and download
// zip.php?type=zip&dir=subdir

// unzip deflate way zipped zip file
// zip.php?type=unzip&name=deflate

$type = $_GET['type'];
$type or exit('die no type to do!');
$name = isset($_GET['name']) ? $_GET['name'].'.zip' : 'zip.zip';
$subdir = $_GET['dir'];
$subdir or die('no sub dir to zip');
set_time_limit(0);
if ($type=='zip') {
	$zip = new ZipArchive();
	if ($zip->open($name, ZipArchive::CREATE) === TRUE) {
		$files = map($dir.$subdir);
		foreach ($files as $file) {
			$dir  = str_replace('\\', '/', $dir);
			$file = str_replace('\\', '/', $file);
			$zip->addFile($file, '_ROOT_/' . str_replace($dir, '', $file));
		}
		$zip->close();
		down($dir.$name);
		echo 'ok';
	} else {
		echo 'failed';
	}
} else if ($type=='unzip') {

	$zip = new ZipArchive();
	if ($zip->open($name) === TRUE) {
		$zip->extractTo(dirname(__FILE__).'/');
		$zip->close();
		echo 'ok';
	} else {
		echo 'failed';
	}
}


function map($directory) {
	$files = array();
	if (file_exists($directory) && is_dir($directory)) {
		foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file) {
			$files[] = $file->getRealPath();
		}
	}
	return $files;
}

function down($file) {
	$filename = $filename ? $filename : basename($file);
	$filesize = filesize($file);
	ob_end_clean();
	@set_time_limit(0);
	if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false) {
		header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		header('Pragma: public');
	} else {
		header('Pragma: no-cache');
	}
	header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
	header('Content-Encoding: none');
	header('Content-Length: ' . $filesize);
	header('Content-Disposition: attachment; filename=' . $filename);
	header('Content-Type: ' . $filetype);
	readfile($file);
	exit;
}
Salin selepas log masuk
web下载网站代码
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Isu terkini
Ikon web awal
daripada 1970-01-01 08:00:00
0
0
0
Bolehkah java digunakan sebagai bahagian belakang web?
daripada 1970-01-01 08:00:00
0
0
0
Apakah keselamatan laman web tersebut?
daripada 1970-01-01 08:00:00
0
0
0
Templat web
daripada 1970-01-01 08:00:00
0
0
0
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan