首页 > php代码

php递归删除目录所有文件

<meta http-equiv="content-type" content="text/html; charset=gb2312">

<?php
function tree($directory)
{
$mydir=dir($directory);
echo "<ul> ";
while($file=$mydir->read()){
if((is_dir("$directory/$file")) and ($file!=".") and ($file!=".."))
{echo "<li><font color="#ff00cc"><b>$file</b></font></li> ";
tree("$directory/$file");
}
else{
    $a = explode('.',$file);
    if($a[1] == 'html' || $a[1] == 'htm')
   {
        //unlink($file);
            echo "<li>$file</li> ";
        }   
   

阅读全文

php ajax分页代码

header("content-type: text/html;charset=gbk");//输出编码,避免中文乱码
?>
<html>
<head>
<title>ajax分页演示</title>
<script language="网页特效" >
var http_request=false;
  function send_request(url){//初始化,指定处理函数,发送请求的函数
    http_request=false;
 //开始初始化xmlhttprequest对象
 if(window.xmlhttprequest){//mozilla浏览器
  http_request=new xmlhttprequest();
  if(http_request.overridemimetype){//设置mime类别
    http_request.overridemimetype("text/xml");
  }
 }
 else if(window.activexobject){//ie浏览器
  try{
   http_request=new activexobject("msxml2.xmlhttp");
  }catch(e){
   try{
   http_request=new activexobject("microsoft.xmlhttp");
   }catch(e){}
  }
    }
 if(!http_request){//异常,创建对象实例失败
  window.alert("创建xmlhttp对象失败!");
  return false;
 }
 http_request.onreadystatechange=processrequest;
 //确定发送请求方式,url,及是否同步执行下段代码
    http_request.open("get",url,true);
 http_request.send(null);
  }
  //处理返回信息的函数
  function processrequest(){
   if(http_request.readystate==4){//判断对象状态
     if(http_request.status==200){//信息已成功返回,开始处理信息
   document.getelementbyid(reobj).innerhtml=http_request.responsetext;
  }
  else{//页面不正常
   alert("您所请求的页面不正常!");
  }
   }
  }
  function dopage(obj,url){
   document.getelementbyid(obj).innerhtml="<font color='green' font-size='12'>正在读取数据...</font>";
   send_request(url);
   reobj=obj;
   }
 
</script>
<style>
/* css教程 document */
#result ul li{
 height:20px;
 width:auto;
 display:block;
 color:#999;
 border:1px solid #999;
 float:left;
 list-style:none;
 font-size:12px;
 margin-left:5px;
 line-height:20px;
 vertical-align:middle;
 text-align:center;
 }
#result ul li a:link{
 width:50px;
 height:20px;
 display:block;
 
 line-height:20px;
 background:#09c;
 border:1px solid #fff;
 color:#fff;
 text-decoration:none;
 }
#result ul li a:hover{
 width:50px;
 height:20px;
 display:block;
 
 line-height:20px;
 background:#09c;
 border:1px solid #fff;
 color:#f60;
 text-decoration:none;
 }
</style>
</head>
<body>
<div id="result">
<?php
$page=isset($_get['page'])?intval($_get['page']):1;        //这句就是获取page=18中的page的值,假如不存在page,那么页数就是1。
$num=10;                                      //每页显示10条数据

阅读全文

php获取文件大小并转换gb,mb,kb代码

function sizecount($filesize) {
 if($filesize >= 1073741824) {
  $filesize = round($filesize / 1073741824 * 100) / 100 . ' gb';
 } elseif($filesize >= 1048576) {
  $filesize = round($filesize / 1048576 * 100) / 100 . ' mb';
 } elseif($filesize >= 1024) {
  $filesize = round($filesize / 1024 * 100) / 100 . ' kb';
 } else {
  $filesize = $filesize . ' bytes';
 }
 return $filesize;
}

阅读全文

ob_start()、ob_end_clean()、ob_get_contents()函数

三个函数吧:"ob_start()、ob_end_clean()、ob_get_contents()"

ob_start():是打开缓冲区的,就是要把您需要生成的静态文件的内容缓存在这里;
ob_get_contents():是读出缓冲区里的内容,下面有代码为例;
ob_end_clean():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来;

阅读全文

php textarea换行符的方法

涉及到textarea中的换行,因为填入的内容是base64编码之后的结果(规范规定,base64编码结果中每76个字符需要加上一个回车换行,即一个" "),在ie下测试,一切ok,但是到了firefox和谷歌浏览器下,总是提示错误,细查一下,发现不同浏览器对于换行符处理不同造成的。

阅读全文

二款php文件上传程序

$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="files";//设置上传域名称
    foreach($_files[$f_input]["error"] as $key => $error){
        $up_error="no";
        if ($error == upload_err_ok){
            $f_name=$_files[$f_input]['name'][$key];//获取上传源文件名
   
            $uploadfile=$uploaddir.strtolower(basename($f_name));
            
            $tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
   $tmp_type=strtolower($tmp_type);
            if(!stristr($f_type,$tmp_type)){
                echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
                $up_error="yes";
            }
            
            if ($_files[$f_input]['size'][$key]>$file_size_max) {
   
                echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_files[$f_input]
['size'][$key]/1024)."kb,大于规定的".($file_size_max/1024)."kb,上传失败!')</script>";
                $up_error="yes";
            }
            
            if (file_exists($uploadfile)&&!$overwrite){
                echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
                $up_error="yes";
            }
             $string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
  $rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdhis").substr($gettime[0],2,6).$rand;
$attdir="./file/"; 
    if(!is_dir($attdir))  
    {  mkdir($attdir);}
            $uploadfile=$attdir.$t.".".$tmp_type;
            if(($up_error!="yes") and (move_uploaded_file($_files[$f_input]['tmp_name']

阅读全文

php把内容中图片连接地址替换成自己的

$files ='<img src="http://img.phprm.com/img/bid_v2/bid_v2_content/p_bid.gif" alt="普通任务" /><img width="272px" height="60px" style="padding-top: 10px;" src="http://img.imgzhubajie.com/img/index_v3/20100611001.gif">';
// 图片地址转换一下   $p=preg_replace('//image//', 'http://qq.ip138.com/image/', $pg[1]);
 $reg = "/<img[^>]*src="(http://(.+)/(.+).(jpg|gif|bmp|bnp))"/isu";
$img=preg_match_all($reg,$files,$imgs);

阅读全文