php 数据库内容以数组形式保存文件中
$res=mysql教程_query("select k1,k2 from ".table('keywords')." ") ;
$str="<?php rn ";
while($rs=mysql_fetch_array($res))
{
$str .="$keyword['".$rs[0]."']='".$rs[1]."';rn";
}
$str.="?>";
file_put_contents("keyword.php",$str);
echo "导出成功";
//方法二
$f=file_get_contents("w1.txt");
$f=str_replace("rn","<br>",$f);//替换换行符
$arr=explode("<br>",$f);
$str="<?php rn ";
foreach($arr as $t)
{
$rs=explode("|",$t);
//不能包含?等特殊符号
$str .="$keyword['".str_replace("?","",$rs[0])."']='".str_replace("?","",$rs[1])."';rn";
}
$str.="?>";
file_put_contents("keyword.php",$str);
echo "导出成功";
//conn.php文件
$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('连接服务器出错');
mysql_select_db($mysql_db) or die("选择数据库出错");
mysql_query("set names 'gbk'");
function table($t)
{
global $mysql_table_prefix;
return $mysql_table_prefix.$t;
}
?>
$fz = new fmzip;
$fz->setzipname("打包文件名");
#打包/压缩
$fz->setsource("待打包目录");
$fz->compress($silent,$compress);
#解包/解压
$fz->settarget("待解包目录");
$fz->uncompress($silent);
*/
class fmzip
{
var $source; //压缩源
var $target; //解压目的文件夹
var $zipname;//压缩文件名
var $handle; //打开压缩文件的句柄
var $silent; //是否输出
var $count_dir; //计数器_文件夹
var $count_file;//计数器_文件
var $dirlist;
function setsource($source)//设置压缩源
{
if(!file_exists($source))
die("source <$source> does not exist.");
$this->source = $source;
}
function settarget($target)//设置解压目的文件夹
{
if(!file_exists($target))
$this->makedir($target);
chdir(dirname($_server['script_filename']));
if(substr($target,-1)=="/")
$target = substr($target,0,strlen($target)-1);
if(!file_exists($target))
{
die("target <$target> does not exist.");
}
$this->target = $target;
}
function setzipname($zipname)//设置压缩文件名
{
if(empty($zipname)) $zipname = "fmzip.fz";
$this->zipname = $zipname;
}
function compress($silent = false, $compress = true) //压缩
{
$this->silent = $silent;
if($silent===false)echo "<pre>compressing...rn";
if(is_file("$this->zipname"))unlink("$this->zipname");
$this->handle = fopen($this->zipname,"w");//创建压缩文件
if($this->handle == null) die("error creating $this->zipname");//打开失败
$this->count_dir = 0; $this->count_file = 0; //初始化计数器
$this->merge($this->source);//压缩
fwrite($this->handle,"-1");//结束标志
fclose($this->handle);//关闭文件
echo "rndirectory: $this->count_dir";
echo "rnfile: $this->count_filern";
if(function_exists("gzcompress") && $compress==true)
{
file_put_contents("$this->zipname.gz",gzcompress(file_get_contents("$this->zipname")));
unlink("$this->zipname");
}
if($silent===false)
{
echo $this->listfile();
echo "</pre>";
}
}
function listfile()
{
if(file_exists("$this->zipname.gz"))
return "<a href="$this->zipname.gz" target="_blank">download $this->zipname.gz</a>";
if(file_exists("$this->zipname"))
return "<a href="$this->zipname" target="_blank">download $this->zipname</a>";
}
function merge($dir)//合并文件、文件夹(递归)
{
/* 说明:不处理link。 */
if(is_dir($dir))//如果压缩源是文件夹
{
$list = scandir($dir);//扫描文件列表
natcasesort($list);
foreach($list as $file)//先处理文件夹
{
$full = "$dir/$file";
if(!is_dir($full)||$file=="."||$file=="..")continue;//只处理文件夹
$this->count_dir++;
if($this->silent===false)
echo "[dir] $fullrn"; //输出提示
fwrite($this->handle,$this->file_info($full));//写入文件夹信息
$this->merge($full);//递归合并下级文件夹
}//文件夹处理完毕;
foreach($list as $file)//处理文件
{
$full = "$dir/$file";
if(!is_file($full)||$file=="."||$file=="..")continue; //只处理文件
$this->count_file++;
if($this->silent===false)
echo "[file] $fullrn";//输出提示
fwrite($this->handle,$this->file_info($full));//写入文件信息
}//文件处理完毕
}
else
{
$this->count_file++;
if($this->silent===false)echo "[file] $fullrn";//输出提示
fwrite($this->handle,$this->file_info($file));//写入文件信息
}
}//end function merge
function file_info($file)
{
$perm = substr(sprintf('%o',fileperms($file)), -3); //权限
$filename = str_replace($this->source,"",$file);
if(is_file($file))//文件
{
$size = filesize($file); //文件大小
return "1rn$filenamern$permrn$sizern".file_get_contents($file)."rn";// .文件内容
}
if(is_dir($file))//目录
return "0rn$filenamern$permrn";
}//end function file_info
function uncompress($silent = false)
{
$this->silent = $silent;
if($silent===false)echo "<pre>uncompressing...rn";
if(substr($this->zipname,-3)==".gz")
$this->zipname = substr($this->zipname,0,strlen($this->zipname)-3);
if(file_exists("$this->zipname.gz"))
{
if(!function_exists(gzuncompress))
die("function gzuncompress is not supported. unable to continue.");
file_put_contents($this->zipname,gzuncompress(file_get_contents("$this->zipname.gz")));
}
$this->handle = fopen($this->zipname,"r");
if($this->handle == null) die("error reading $this->zipname");//打开失败
$count = 0;
while(1)
{
$count ++;
$type = $this->read_line(); //读取类型
if($type === "-1")break;//处理完毕,退出
$filename = $this->target.$this->read_line();//读取文件名
$permission = $this->read_line();//读取权限
/* <文件夹> [0]n[file_name]n[perm]n */
if($type === "0")//目录
{
if($this->silent === false)//输出提示
echo "[dir] $filename [$permission]rn";
$this->makedir($filename);//创建文件夹
chdir(dirname($_server['script_filename']));
chmod($filename,$permission);
$this->dirlist[$filename] = 1;
continue;
}
/* <文件> [1]n[file_name]n[perm]n[size]n[contents]n */
if($type === "1")//文件
{
$this->count_file++;
$size = $this->read_line(); //读取文件大小
if($this->silent === false)//输出提示
echo "[file] $filename [$permission] [size = $size]rn";
if($size!=0)
{
$fp = fopen($filename,"w");
$contents = fread($this->handle,$size);
fwrite($fp,$contents);
fclose($fp);
chmod($filename,$permission);
}
$this->read_line();//内容后的一个回车
continue;
}
}
$this->count_dir = count($this->dirlist);
if($silent===false)
echo "ndirectory: $this->count_dir";
echo "nfile: $this->count_filen</pre>n";
fclose($this->handle);
if(file_exists("$this->zipname.gz"))unlink("$this->zipname");
}//end function uncompress;
function read_line()
{
$a = fgets($this->handle);
$a = str_replace("rn","",$a);
$a = str_replace("n","",$a);
return $a;
}
function makedir($full)
{
list($a,$b) = split("/",$full,2);
if($a == "") return;
if(file_exists($a)&&!is_dir($a))die("can't create dir $a");
if(!file_exists($a))@mkdir($a);
chdir($a);
if($b!=="")
$this->makedir($b);
chdir("..");
}//end function makedir
} //end class fmzip
/*
使用方法:
#必须
include("包含这个class的php文件");
$fz = new fmzip;
$fz->setzipname("打包文件名");
#打包/压缩
$fz->setsource("待打包目录");
$fz->compress($silent,$compress);
#解包/解压
$fz->settarget("待解包目录");
$fz->uncompress($silent);
$silent : true|false (不加引号!) 是否产生输出 默认为true,不产生
$compress : true|false (不加引号!) 是否压缩 默认为true,压缩
database config
*/
代码如下 | 复制代码 |
$db_host = 'localhost'; $link = mysql_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection'); mysql_select_db($db_database,$link);
$comment = mysql_real_escape_string(nl2br(strip_tags($_post['comment']))); $addon=''; mysql_query("insert into wave_comments set usr='".$user."', comment='".$comment."', dt=now()".$addon); if(mysql_affected_rows($link)==1) |
sql
--
-- table structure for table `wave_comments`
--
create table `wave_comments` (
`id` int(11) not null auto_increment,
`parent` int(11) not null default '0',
`usr` varchar(16) collate utf8_unicode_ci not null default '',
`comment` text collate utf8_unicode_ci not null,
`dt` datetime not null default '0000-00-00 00:00:00',
primary key (`id`),
key `parent` (`parent`,`id`)
) engine=myisam default charset=utf8 collate=utf8_unicode_ci;
--
-- dumping data for table `wave_comments`
--
insert into `wave_comments` values(1, 0, 'tutorialzine', 'this is a demo for a tutorialzine tutorial about creating a google wave-like history slider.<br /><br />rnto get started, just drag the slider above, and this thread will be reverted to a past state.', '2009-10-24 03:58:08');
insert into `wave_comments` values(2, 0, 'curious', 'is html allowed in the comments?', '2009-10-24 03:59:44');
insert into `wave_comments` values(3, 2, 'tutorialzine', 'nope. also the messages in this demo are deleted every hour to prevent spamming.', '2009-10-24 04:00:15');
insert into `wave_comments` values(4, 1, 'tutorialzine', 'in this tutorial we are using <b>php</b>, <b>mysql</b>, <b>jquery</b> and <b>css教程</b>. the slider was created with <b>jquery ui</b>. <a href="http://111cn.net/2009/10/google-wave-history-slider-jquery/" target="_blank">view the tutorial</a>.', '2009-10-24 04:01:34');
insert into `wave_comments` values(5, 2, 'curious', 'thanks! also i noticed that you can click, rather than drag the slider.great!', '2009-10-24 04:11:48');
代码如下 | 复制代码 |
<!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.111cn.net/tr/xhtml1/dtd/xhtml1-strict.dtd"> #drag_container li #drag_container li.doc, #drag_container li.doc-last #drag_container .folder-open, #drag_container .folder-open-last <body> </body> </html> php文件 |
源码下载
http://down.111cn.net/down/code/jquery/2010/1014/21200.html
效果预览
http://g.111cn.net/javascript/code/20101012/tree
html代码
代码如下 | 复制代码 |
<input type= "file " id= "userfile " name= "userfile "> <input type= "submit " name= "upload " value= "上传 "> |
处理上传php代码
代码如下 | 复制代码 |
<?php function do_upload($upload_dir,$upload_url) { $temp_name = $_files[ 'userfile '][ 'tmp_name ']; $file_name = $_files[ 'userfile '][ 'name ']; $file_name = str_replace( "\ ", " ",$file_name); $file_name = str_replace( " ' ", " ",$file_name); $file_path = $upload_dir.$file_name; $thistime=explode( "- ",date( "y-m-d-h-i-s ")); $thistime=mktime(); $filename=$thistime.substr($file_name,strrpos($file_name, ". ")); //文件名检查 if($file_name = ' ') { echo "文件名无效。 "; exit; } if(@move_uploaded_file($_files[ 'userfile '][ 'tmp_name '],$upload_dir.$filename)) { echo "上传成功。 "; echo " <meta http-equiv= "refresh " content= "1;url=www.aimeige.com.cn.php "> "; exit; }else { echo "上传失败。 "; echo " <meta http-equiv= "refresh " content= "1;url=www.111cn.net.php "> "; exit; } echo "end "; } ?> |
代码如下 | 复制代码 |
调用方法 |
代码如下 | 复制代码 |
$upload_dir ='down.111cn.net'; $upload_url='www.111cn.net'; |
代码如下 | 复制代码 |
do_upload($upload_dir,$upload_url) ; |
相关文章
- 下面小编来给大家演示几个php操作zip文件的实例,我们可以读取zip包中指定文件与删除zip包中指定文件,下面来给大这介绍一下。 从zip压缩文件中提取文件 代...2016-11-25
- 在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
- 操作类就是把一些常用的一系列的数据库或相关操作写在一个类中,这样调用时我们只要调用类文件,如果要执行相关操作就直接调用类文件中的方法函数就可以实现了,下面整理了...2016-11-25
- 本文给大家分享C#连接SQL数据库和查询数据功能的操作技巧,本文通过图文并茂的形式给大家介绍的非常详细,需要的朋友参考下吧...2021-05-17
Jupyter Notebook读取csv文件出现的问题及解决
这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06- 这篇文章主要介绍了C#从数据库读取图片并保存的方法,帮助大家更好的理解和使用c#,感兴趣的朋友可以了解下...2021-01-16
- 这篇文章主要介绍了Python 图片转数组,二进制互转操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-09
- 这篇文章主要介绍了Intellij IDEA连接Navicat数据库的方法,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借价值,需要的朋友可以参考下...2021-03-25
- 在开发过程中,我们经常会将日期时间的毫秒数存放到数据库,但是它对应的时间看起来就十分不方便,我们可以使用一些函数将毫秒转换成date格式。 一、 在MySQL中,有内置的函数from_unixtime()来做相应的转换,使用如下: 复制...2014-05-31
- 有时我们接受或下载到的PSD文件打开是空白的,那么我们要如何来解决这个 问题了,下面一聚教程小伙伴就为各位介绍Photoshop打开PSD文件空白解决办法。 1、如我们打开...2016-09-14
- 本文章提供在量的数据中级操作实例有如对键名比较计算数组的差集 计算差集 给指定数组中插入一个元素 反转数组 交集赋值新的数组实例。 //定义回调函数 funct...2016-11-25
- C#使用System.IO中的文件操作方法在Windows系统中处理本地文件相当顺手,这里我们还总结了在Oracle中保存文件的方法,嗯,接下来就来看看整理的C#操作本地文件及保存文件到数据库的基本方法总结...2020-06-25
- 这篇文章主要介绍了解决python 使用openpyxl读写大文件的坑,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-13
- 这篇文章主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要介绍了C#二维数组基本用法,以实例形式分析了C#中二维数组的定义、初始化、遍历及打印等用法,具有一定参考借鉴价值,需要的朋友可以参考下...2020-06-25
- 这篇文章主要为大家详细介绍了SpringBoot实现excel文件生成和下载,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-02-09
- 下面一段代码给大家介绍php curl模拟post请求的示例代码,具体代码如下: <?php$uri = "http://www.cnblogs.com/test.php";//这里换成自己的服务器的地址// 参数数组$data = array ( 'name' => 'tanteng'// 'passwor...2015-11-24
- Array数组在C#中同样是最基本的数据结构,下面为大家C#数组的常用操作方法小结,皆为细小的代码段,欢迎收看收藏...2020-06-25
- 通过内网连另外一台机器的mysql服务, 确发现速度N慢! 等了大约几十秒才等到提示输入密码。 但是ping mysql所在服务器却很快! 想到很久之前有过类似的经验, telnet等一些服务在连接请求的时候,会做一些反向域名解析(如果...2015-10-21
- 某些时候,例如为了搭建一个测试环境,或者克隆一个网站,需要复制一个已存在的mysql数据库。使用以下方法,可以非常简单地实现。假设已经存在的数据库名字叫db1,想要复制一份,命名为newdb。步骤如下:1. 首先创建新的数据库newd...2015-10-21