当前位置: 编程技术>php
本页文章导读:
▪php在线打包程序源码
实现打包功能~轻松方便!压缩比虽比winrar差那么一点 但是也没啥关系 毕竟只打包做下载 省下了自己去服务器上把站点打包 如果服务器不是自己的就更麻烦了 要让别人帮忙打下包 代码.........
▪php对gzip文件或者字符串解压实例参考
其实php对gzip解压很简单,用内置的gzdecode函数就可以了,不过很可惜我配置了半天也无法支持gzdecode函数,所以只好变通一下: 代码如下: if (!function_exists('gzdecode')) { .........
▪php+mysql写的简单留言本实例代码
guestbook.php: <head> <meta http-equiv="Content-Language" c> <meta http-equiv="Content-Type" c> <title></title> <STYLE>A:link { COLOR: #002878; TEXT-DECORATION: none } A:vis.........
[1]php在线打包程序源码
来源: 互联网 发布时间: 2013-11-30
实现打包功能~轻松方便!压缩比虽比winrar差那么一点 但是也没啥关系 毕竟只打包做下载
省下了自己去服务器上把站点打包 如果服务器不是自己的就更麻烦了 要让别人帮忙打下包
<?php
//php压缩目录成zip包
//作者:小锋
$button=$_POST['button'];
if($button=="开始打包")
{
$zip = new ZipArchive();
$filename = "./".date("Y-m-d")."_".md5(time())."_jackfeng.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("无法创建 <$filename>\n");
}
$files = listdir();
foreach($files as $path)
{
$zip->addFile($path,str_replace("./","",str_replace("\\","/",$path)));
}
echo "压缩完成,共压缩了: " . $zip->numFiles . "个文件\n";
$zip->close();
}
Function listdir($start_dir='.') {
$files = array();
if (is_dir($start_dir)) {
$fh = opendir($start_dir);
while (($file = readdir($fh)) !== false) {
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
$filepath = $start_dir . '/' . $file;
if ( is_dir($filepath) )
$files = array_merge($files, listdir($filepath));
else
array_push($files, $filepath);
}
closedir($fh);
} else {
$files = false;
}
return $files;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>在线打包工具</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="">
<hr size="1">
<h3><a href="/blog_article/.html">在线打包工具</a></h3>
<P> <input type="submit" name="button" value="开始打包" /></P>
<P>说明:点开始打包,之后,就是耐心等待打包完成了,根据网站文件多少,需要的时间可能会很长。打包完成之后,压缩包会存放在要打包的站点目录下,以<span >打包时间+不定长随机字符串+jackfeng.zip</span>这样命名,请登陆ftp后下载。</P>
</form>
</body>
</html>
省下了自己去服务器上把站点打包 如果服务器不是自己的就更麻烦了 要让别人帮忙打下包
代码如下:
<?php
//php压缩目录成zip包
//作者:小锋
$button=$_POST['button'];
if($button=="开始打包")
{
$zip = new ZipArchive();
$filename = "./".date("Y-m-d")."_".md5(time())."_jackfeng.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("无法创建 <$filename>\n");
}
$files = listdir();
foreach($files as $path)
{
$zip->addFile($path,str_replace("./","",str_replace("\\","/",$path)));
}
echo "压缩完成,共压缩了: " . $zip->numFiles . "个文件\n";
$zip->close();
}
Function listdir($start_dir='.') {
$files = array();
if (is_dir($start_dir)) {
$fh = opendir($start_dir);
while (($file = readdir($fh)) !== false) {
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
$filepath = $start_dir . '/' . $file;
if ( is_dir($filepath) )
$files = array_merge($files, listdir($filepath));
else
array_push($files, $filepath);
}
closedir($fh);
} else {
$files = false;
}
return $files;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>在线打包工具</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<form name="form1" method="post" action="">
<hr size="1">
<h3><a href="/blog_article/.html">在线打包工具</a></h3>
<P> <input type="submit" name="button" value="开始打包" /></P>
<P>说明:点开始打包,之后,就是耐心等待打包完成了,根据网站文件多少,需要的时间可能会很长。打包完成之后,压缩包会存放在要打包的站点目录下,以<span >打包时间+不定长随机字符串+jackfeng.zip</span>这样命名,请登陆ftp后下载。</P>
</form>
</body>
</html>
[2]php对gzip文件或者字符串解压实例参考
来源: 互联网 发布时间: 2013-11-30
其实php对gzip解压很简单,用内置的gzdecode函数就可以了,不过很可惜我配置了半天也无法支持gzdecode函数,所以只好变通一下:
if (!function_exists('gzdecode')) {
function gzdecode ($data) {
$flags = ord(substr($data, 3, 1));
$headerlen = 10;
$extralen = 0;
$filenamelen = 0;
if ($flags & 4) {
$extralen = unpack('v' ,substr($data, 10, 2));
$extralen = $extralen[1];
$headerlen += 2 + $extralen;
}
if ($flags & 8) // Filename
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 16) // Comment
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 2) // CRC at end of file
$headerlen += 2;
$unpacked = @gzinflate(substr($data, $headerlen));
if ($unpacked === FALSE)
$unpacked = $data;
return $unpacked;
}
}
调用方法很简单:
$f=@file_get_contents("http://www.");
echo gzdecode($f);
代码如下:
if (!function_exists('gzdecode')) {
function gzdecode ($data) {
$flags = ord(substr($data, 3, 1));
$headerlen = 10;
$extralen = 0;
$filenamelen = 0;
if ($flags & 4) {
$extralen = unpack('v' ,substr($data, 10, 2));
$extralen = $extralen[1];
$headerlen += 2 + $extralen;
}
if ($flags & 8) // Filename
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 16) // Comment
$headerlen = strpos($data, chr(0), $headerlen) + 1;
if ($flags & 2) // CRC at end of file
$headerlen += 2;
$unpacked = @gzinflate(substr($data, $headerlen));
if ($unpacked === FALSE)
$unpacked = $data;
return $unpacked;
}
}
调用方法很简单:
代码如下:
$f=@file_get_contents("http://www.");
echo gzdecode($f);
[3]php+mysql写的简单留言本实例代码
来源: 互联网 发布时间: 2013-11-30
guestbook.php:
<head>
<meta http-equiv="Content-Language" c>
<meta http-equiv="Content-Type" c>
<title></title>
<STYLE>A:link {
COLOR: #002878; TEXT-DECORATION: none
}
A:visited {
COLOR: #002878; TEXT-DECORATION: none
}
A:active {
TEXT-DECORATION: none
}
A:hover {
COLOR: #cc1111; TEXT-DECORATION: none
}
P {
COLOR: #002878; FONT-SIZE: 9pt
}
TABLE {
COLOR: #002878; FONT-SIZE: 9pt
}
LI {
COLOR: #002878; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt
}
UL {
COLOR: #002878; FONT-SIZE: 9pt
}
}
</STYLE>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="574" height="312">
</center>
<tr>
<td><p align="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<td width="574" height="272" valign="top">
<form method="POST" action="/blog_article/ly.html">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<center>
<tr>
<td width="26%" align="right">
姓名:</td>
<td width="74%"><input
type="text" name="T1" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
EMAIL:</td>
<td width="74%"><input name="T2" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
个人主页:</td>
<td width="74%"><input name="T3" size="13" value="http://";></td>
</tr>
<tr>
<td width="26%" align="right">
主题:</td>
<td width="74%"><input name="T4" size="13"></td>
</tr>
<tr>
<td width="26%" align="right" valign="top">
留言:</td>
<td width="74%"><textarea rows="10" name="S1" cols="45" ></textarea></td>
</tr>
<tr>
<td width="100%" align="right" colspan="2">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="提交" name="B1"> <input type="reset" value="重写" name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hr size='1' color='#6666FF'>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="603" height="294">
<tr>
<td width="603" height="294">
<?
include ("connect.rec");
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM guestbook");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=0;
}
//查询结果(这里是每页20条,但你自己完全可以改变它)
//$result=mysql_query("SELECT * from guestbook ORDER BY time desc LIMIT $offset, 5");
$result=mysql_query("SELECT * from guestbook LIMIT $offset, 5");
//显示返回的5条记录
while ($data=mysql_fetch_array($result))
{
printf("姓名:<font color='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<font color='#3366FF'>%s</font><br>",$data["mail"]);
printf("个人主页:<font color='#3366FF'>%s</font><br>",$data["url"]);
printf("来自:<font color='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言时间:<font color='#3366FF'>%s</font><br>",$data["time"]);
printf("主题:<font color='#3366FF'>%s</font><br>",$data["title"]);
printf("内容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666FF'>");
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print "<a href="/blog_article/$PHP_SELF/offset/$preoffset.html">前一页</a> n";
}
//计算总共需要的页数
$pages=ceil($nr/5); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="/blog_article/$PHP_SELF/offset/$newoffset.html">$i</a> n";
}
//检查是否是最后一页
$next = $offset+5;
if ($next<$nr)
{
print "<a href="/blog_article/$PHP_SELF/offset/$next.html">下一页</a> n";
}
printf("<a href='javascript:history.back()'>返回</a>")
?>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
ly.php:
<?
include ("connect.rec");
$name = $T1;
$mail = $T2;
$url = $T3;
$title = $T4;
$time = date( "Y-m-j H:i:s" );
$ip = getenv("REMOTE_ADDR");
$ly = $S1;
$result = mysql_query("insert into guestbook (name,mail,url,ip,time,title,ly) values ('$name','$mail','$url','$ip','$time','$title','$ly')");
if ($result == 1)
{
echo("留言成功!");
printf("<script language='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失败!");
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
<head>
<meta http-equiv="Content-Language" c>
<meta http-equiv="Content-Type" c>
<title></title>
<STYLE>A:link {
COLOR: #002878; TEXT-DECORATION: none
}
A:visited {
COLOR: #002878; TEXT-DECORATION: none
}
A:active {
TEXT-DECORATION: none
}
A:hover {
COLOR: #cc1111; TEXT-DECORATION: none
}
P {
COLOR: #002878; FONT-SIZE: 9pt
}
TABLE {
COLOR: #002878; FONT-SIZE: 9pt
}
LI {
COLOR: #002878; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt
}
UL {
COLOR: #002878; FONT-SIZE: 9pt
}
}
</STYLE>
</head>
<body>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="574" height="312">
</center>
<tr>
<td><p align="center">高三<6>班留言本本</br></td>
</tr>
<tr>
<td width="574" height="272" valign="top">
<form method="POST" action="/blog_article/ly.html">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<center>
<tr>
<td width="26%" align="right">
姓名:</td>
<td width="74%"><input
type="text" name="T1" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
EMAIL:</td>
<td width="74%"><input name="T2" size="13"></td>
</tr>
<tr>
<td width="26%" align="right">
个人主页:</td>
<td width="74%"><input name="T3" size="13" value="http://";></td>
</tr>
<tr>
<td width="26%" align="right">
主题:</td>
<td width="74%"><input name="T4" size="13"></td>
</tr>
<tr>
<td width="26%" align="right" valign="top">
留言:</td>
<td width="74%"><textarea rows="10" name="S1" cols="45" ></textarea></td>
</tr>
<tr>
<td width="100%" align="right" colspan="2">
</td>
</tr>
</table>
<p align="center">
<input type="submit" value="提交" name="B1"> <input type="reset" value="重写" name="B2"></p>
</form>
</center>
</td>
</tr>
</table>
<hr size='1' color='#6666FF'>
</div>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" width="603" height="294">
<tr>
<td width="603" height="294">
<?
include ("connect.rec");
$qh=mysql_query("SELECT COUNT(*) AS rcnt FROM guestbook");
$data=mysql_fetch_array($qh);
$nr=$data["rcnt"];
//判断偏移量参数是否传递给了脚本,如果没有就使用默认值0
if (empty($offset))
{
$offset=0;
}
//查询结果(这里是每页20条,但你自己完全可以改变它)
//$result=mysql_query("SELECT * from guestbook ORDER BY time desc LIMIT $offset, 5");
$result=mysql_query("SELECT * from guestbook LIMIT $offset, 5");
//显示返回的5条记录
while ($data=mysql_fetch_array($result))
{
printf("姓名:<font color='#000000'>%s</font><br>",$data["name"]);
printf("EMAIL:<font color='#3366FF'>%s</font><br>",$data["mail"]);
printf("个人主页:<font color='#3366FF'>%s</font><br>",$data["url"]);
printf("来自:<font color='#3366FF'>%s</font><br>",$data["ip"]);
printf("留言时间:<font color='#3366FF'>%s</font><br>",$data["time"]);
printf("主题:<font color='#3366FF'>%s</font><br>",$data["title"]);
printf("内容:<font color='#000000'>%s</font><br>",$data["ly"]);
printf("<hr size='1' color='#6666FF'>");
}
//下一步,要写出到其它页面的链接
if($offset) //如果偏移量是0,不显示前一页的链接
{
$preoffset=$offset-5;
print "<a href="/blog_article/$PHP_SELF/offset/$preoffset.html">前一页</a> n";
}
//计算总共需要的页数
$pages=ceil($nr/5); //$pages变量现在包含所需的页数
for ($i=1; $i <= $pages; $i++)
{
$newoffset=5*$i-5;
print "<a href="/blog_article/$PHP_SELF/offset/$newoffset.html">$i</a> n";
}
//检查是否是最后一页
$next = $offset+5;
if ($next<$nr)
{
print "<a href="/blog_article/$PHP_SELF/offset/$next.html">下一页</a> n";
}
printf("<a href='javascript:history.back()'>返回</a>")
?>
</td>
</tr>
</table>
</center>
</div>
</body>
</html>
ly.php:
<?
include ("connect.rec");
$name = $T1;
$mail = $T2;
$url = $T3;
$title = $T4;
$time = date( "Y-m-j H:i:s" );
$ip = getenv("REMOTE_ADDR");
$ly = $S1;
$result = mysql_query("insert into guestbook (name,mail,url,ip,time,title,ly) values ('$name','$mail','$url','$ip','$time','$title','$ly')");
if ($result == 1)
{
echo("留言成功!");
printf("<script language='javascript'>");
printf("location='guestbook.php'");
printf("</script>");
}
else
{
echo("留言失败!");
printf("<a href='javascript:history.back()'>返回</a>");
}
?>
最新技术文章: