2017年7月

修改WampServer的默认80端口

修改httpd.conf文件中Listen 81ServerName localhost:81
重启wamp,就可以生效了。但是LocalhostphpMyAdmin依旧是默认的80端口。找到wamp安装目录下的wampmanager.tpl文件修改:

Type: item; Caption: "${w_localhost}"; Action: run; FileName: "${c_navigator}"; Parameters: "http://localhost:81/"; Glyph: 5
;WAMPPROJECTSUBMENU

Type: item; Caption: "${w_phpmyadmin}"; Action: run; FileName: "${c_navigator}"; Parameters: "http://localhost:81/phpmyadmin/"; Glyph: 5

phpzip系统压缩类压缩,php压缩类,php在线压缩

<?php

class PHPZip {
Private $StrPath = "";
Private $datasec = array();
Private $ctrl_dir = array();
Private $eof_ctrl_dir = "\x50\x4b\x05\x06\x00\x00\x00\x00";
Private $old_offset = 0;

//压缩后下载  
function DownLoad($curdir, $zipfilename, $out) {
    $zipfilename = StrToLower($zipfilename);
    $curdir = Str_iReplace(basename($curdir), "", $curdir);
    chdir($curdir . $this->StrPath);

    header('Content-Encoding: none');
    header('Content-Type: application/zip');
    header('Content-Disposition: attachment ; filename=' . Str_Replace(".zip", "", basename($zipfilename)) . '.zip');
    header('Pragma: no-cache');
    header('Expires: 0');
    print($out);
}

//压缩后保存在服务器,默认在/@Upload下  
function SaveFile($curdir, $zipfilename, $out) {
    $curdir = Str_iReplace(basename($curdir), "", $curdir);
    chdir($curdir . $this->StrPath);
    $fp = fopen($zipfilename, "wb");
    fwrite($fp, $out, strlen($out));
    fclose($fp);
}

//函数用途:压缩文件夹,递归逐层进行  
//参数详解:$dir需要压缩的目录,$zipfilename压缩后的文件名及存放路径,$Todo处理方式1提供下载2保存文件在服务器  
function ZipDir($dir, $zipfilename, $Todo) {
    IF (!@function_exists('gzcompress')) {
        Return 0;
    }
    @set_time_limit("0");
    $this->openFile($dir, $zipfilename);
    $out = $this->filezip();

    Switch ($Todo) {
        Case "1":
            $this->DownLoad(__FILE__, $zipfilename, $out);
            Break;
        Case "2":
            $this->SaveFile(__FILE__, $zipfilename, $out);
            Break;
    }
}

//函数用途:压缩文件,可以是单个也可以是数组的多个  
//参数详解:$file需要压缩的文件(可为数组),$zipfilename压缩后的文件名及存放路径,$Todo处理方式1提供下载2保存文件在服务器  
function ZipFile($file, $zipfilename, $Todo) {
    IF (!@function_exists('gzcompress')) {
        Return 0;
    }
    IF (is_array($file)) {

        Foreach ($file as $filename) {
            IF (is_file($filename)) {
                $fd = fopen($filename, "rb");
                $content = @fread($fd, filesize($filename));
                fclose($fd);

                $filename = basename($filename);
                $this->addFile($content, $filename);
            }
        }
    } Else {
        IF (is_file($file)) {
            $fd = fopen($file, "rb");
            $content = @fread($fd, filesize($file));
            fclose($fd);
            $file = basename($file);
            $this->addFile($content, $file);
        }
    }
    $out = $this->filezip();

    Switch ($Todo) {
        Case "1":
            $this->DownLoad(__FILE__, $zipfilename, $out);
            Break;
        Case "2":
            $this->SaveFile(__FILE__, $zipfilename, $out);
            Break;
    }
}

//递归取得下层文件夹下的文件  
function openFile($path, $zipName) {
    $temp_path = $path;
    $temp_zip_path = $zipName;
    IF ($handle = @opendir($path)) {
        While (false !== ($file = readdir($handle))) {
            IF ($file != '.' and $file != '..') {
                IF (preg_match('/\./', $file . @basename())) {
                    $fd = fopen($path . '/' . $file, "r");
                    $fileValue = @fread($fd, 1024000);
                    fclose($fd);
                    $this->addFile($fileValue, $path . '/' . $file);
                } Else {
                    $this->openFile($path . '/' . $file, $zipName . '/' . $file);
                }
            }
        }
        $zipName = $temp_zip_path;
        $path = $temp_path;
        closedir($handle);
    }
}

function addFile($data, $name, $time = 0) {
    $name = str_replace('\\', '/', $name);
    $name = str_replace('./', '', str_replace('../', '', $name));
    $dtime = dechex($this->unix2DosTime($time));
    $hexdtime = '\x' . $dtime[6] . $dtime[7] . '\x' . $dtime[4] . $dtime[5] . '\x' . $dtime[2] . $dtime[3] . '\x' . $dtime[0] . $dtime[1];
    Eval('$hexdtime="' . $hexdtime . '";');

    $fr = "\x50\x4b\x03\x04";
    $fr.="\x14\x00";
    $fr.="\x00\x00";
    $fr.="\x08\x00";
    $fr.=$hexdtime;

    $unc_len = strlen($data);
    $crc = crc32($data);
    $zdata = gzcompress($data);
    $c_len = strlen($zdata);
    $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2);
    $fr.=pack('V', $crc);
    $fr.=pack('V', $c_len);
    $fr.=pack('V', $unc_len);
    $fr.=pack('v', strlen($name));
    $fr.=pack('v', 0);
    $fr.=$name;
    $fr.=$zdata;
    $fr.=pack('V', $crc);
    $fr.=pack('V', $c_len);
    $fr.=pack('V', $unc_len);

    $this->datasec[] = $fr;
    $new_offset = strlen(implode('', $this->datasec));

    $cdrec = "\x50\x4b\x01\x02";
    $cdrec.="\x00\x00";
    $cdrec.="\x14\x00";
    $cdrec.="\x00\x00";
    $cdrec.="\x08\x00";
    $cdrec.=$hexdtime;
    $cdrec.=pack('V', $crc);
    $cdrec.=pack('V', $c_len);
    $cdrec.=pack('V', $unc_len);
    $cdrec.=pack('v', strlen($name));
    $cdrec.=pack('v', 0);
    $cdrec.=pack('v', 0);
    $cdrec.=pack('v', 0);
    $cdrec.=pack('v', 0);
    $cdrec.=pack('V', 32);
    $cdrec.=pack('V', $this->old_offset);
    $this->old_offset = $new_offset;
    $cdrec.=$name;
    $this->ctrl_dir[] = $cdrec;
}

function filezip() {
    $data = implode('', $this->datasec);
    $ctrldir = implode('', $this->ctrl_dir);

    Return
            $data . $ctrldir . $this->eof_ctrl_dir .
            pack('v', sizeof($this->ctrl_dir)) .
            pack('v', sizeof($this->ctrl_dir)) .
            pack('V', strlen($ctrldir)) .
            pack('V', strlen($data)) . "\x00\x00";
}

function unix2DosTime($unixtime = 0) {
    $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
    IF ($timearray['year'] < 1980) {
        $timearray['year'] = 1980;
        $timearray['mon'] = 1;
        $timearray['mday'] = 1;
        $timearray['hours'] = 0;
        $timearray['minutes'] = 0;
        $timearray['seconds'] = 0;
    }
    Return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);
}

/*
  解压缩部分
  用途:解压缩文件
  参数:$zn需要解压缩的zip文件及路径,$to解压缩的目的地
 */

function Unzip_File($zn, $to, $index = Array(-1)) {
    error_reporting(0);
    $ok = 0;
    $zip = @fopen($zn, 'rb');
    IF (!$zip) {
        Return(-1);
    }
    $cdir = $this->ReadCentralDir($zip, $zn);
    $pos_entry = $cdir['offset'];

    IF (!is_array($index)) {
        $index = array($index);
    }
    For ($i = 0; $index[$i]; $i++) {
        IF (intval($index[$i]) != $index[$i] || $index[$i] > $cdir['entries']) {
            Return(-1);
        }
    }

    For ($i = 0; $i < $cdir['entries']; $i++) {
        @fseek($zip, $pos_entry);
        $header = $this->ReadCentralFileHeaders($zip);
        $header['index'] = $i;
        $pos_entry = ftell($zip);
        @rewind($zip);
        fseek($zip, $header['offset']);
        IF (in_array("-1", $index) || in_array($i, $index)) {
            $stat[$header['filename']] = $this->ExtractFile($header, $to, $zip);
        }
    }
    fclose($zip);
    Return $stat;
}

//取得压缩包内的文件信息  
function get_List($zip_name) {
    $zip = @fopen($zip_name, 'rb');
    IF (!$zip) {
        Return(0);
    }
    $centd = $this->ReadCentralDir($zip, $zip_name);

    @rewind($zip);
    @fseek($zip, $centd['offset']);

    For ($i = 0; $i < $centd['entries']; $i++) {
        $header = $this->ReadCentralFileHeaders($zip);
        $header['index'] = $i;
        $info['filename'] = $header['filename'];
        $info['stored_filename'] = $header['stored_filename'];
        $info['size'] = $header['size'];
        $info['compressed_size'] = $header['compressed_size'];
        $info['crc'] = strtoupper(dechex($header['crc']));
        $info['mtime'] = $header['mtime'];
        $info['comment'] = $header['comment'];
        $info['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0;
        $info['index'] = $header['index'];
        $info['status'] = $header['status'];
        $ret[] = $info;
        unset($header);
    }
    Return $ret;
}

function ReadFileHeader($zip) {
    $binary_data = fread($zip, 30);
    $data = unpack('vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data);

    $header['filename'] = fread($zip, $data['filename_len']);
    IF ($data['extra_len'] != 0) {
        $header['extra'] = fread($zip, $data['extra_len']);
    } Else {
        $header['extra'] = '';
    }

    $header['compression'] = $data['compression'];
    $header['size'] = $data['size'];
    $header['compressed_size'] = $data['compressed_size'];
    $header['crc'] = $data['crc'];
    $header['flag'] = $data['flag'];
    $header['mdate'] = $data['mdate'];
    $header['mtime'] = $data['mtime'];

    IF ($header['mdate'] && $header['mtime']) {
        $hour = ($header['mtime'] & 0xF800) >> 11;
        $minute = ($header['mtime'] & 0x07E0) >> 5;
        $seconde = ($header['mtime'] & 0x001F) * 2;
        $year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
        $month = ($header['mdate'] & 0x01E0) >> 5;
        $day = $header['mdate'] & 0x001F;
        $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
    } Else {
        $header['mtime'] = time();
    }

    $header['stored_filename'] = $header['filename'];
    $header['status'] = "ok";
    Return $header;
}

function ReadCentralFileHeaders($zip) {
    $binary_data = fread($zip, 46);
    $header = unpack('vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data);

    IF ($header['filename_len'] != 0)
        $header['filename'] = fread($zip, $header['filename_len']);
    Else
        $header['filename'] = '';

    IF ($header['extra_len'] != 0)
        $header['extra'] = fread($zip, $header['extra_len']);
    Else
        $header['extra'] = '';

    IF ($header['comment_len'] != 0)
        $header['comment'] = fread($zip, $header['comment_len']);
    Else
        $header['comment'] = '';

    IF ($header['mdate'] && $header['mtime']) {
        $hour = ($header['mtime'] & 0xF800) >> 11;
        $minute = ($header['mtime'] & 0x07E0) >> 5;
        $seconde = ($header['mtime'] & 0x001F) * 2;
        $year = (($header['mdate'] & 0xFE00) >> 9) + 1980;
        $month = ($header['mdate'] & 0x01E0) >> 5;
        $day = $header['mdate'] & 0x001F;
        $header['mtime'] = mktime($hour, $minute, $seconde, $month, $day, $year);
    } Else {
        $header['mtime'] = time();
    }
    $header['stored_filename'] = $header['filename'];
    $header['status'] = 'ok';
    IF (substr($header['filename'], -1) == '/')
        $header['external'] = 0x41FF0010;
    Return $header;
}

function ReadCentralDir($zip, $zip_name) {
    $size = filesize($zip_name);
    IF ($size < 277) {
        $maximum_size = $size;
    } Else {
        $maximum_size = 277;
    }

    @fseek($zip, $size - $maximum_size);
    $pos = ftell($zip);
    $bytes = 0x00000000;

    While ($pos < $size) {
        $byte = @fread($zip, 1);
        $bytes = ($bytes << 8) | Ord($byte);
        IF ($bytes == 0x504b0506) {
            $pos++;
            break;
        }
        $pos++;
    }

    $data = unpack('vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($zip, 18));

    IF ($data['comment_size'] != 0) {
        $centd['comment'] = fread($zip, $data['comment_size']);
    } Else {
        $centd['comment'] = '';
    }
    $centd['entries'] = $data['entries'];
    $centd['disk_entries'] = $data['disk_entries'];
    $centd['offset'] = $data['offset'];
    $centd['disk_start'] = $data['disk_start'];
    $centd['size'] = $data['size'];
    $centd['disk'] = $data['disk'];
    Return $centd;
}

function ExtractFile($header, $to, $zip) {
    $header = $this->readfileheader($zip);

    IF (substr($to, -1) != "/")
        $to .= "/";
    IF (!@is_dir($to))
        @mkdir($to, 0777);

    $pth = explode("/", dirname($header['filename']));
    For ($i = 0; isset($pth[$i]); $i++) {
        IF (!$pth[$i])
            continue;
        $pthss .= $pth[$i] . "/";
        IF (!is_dir($to . $pthss))
            @mkdir($to . $pthss, 0777);
    }
    IF (!($header['external'] == 0x41FF0010) && !($header['external'] == 16)) {
        IF ($header['compression'] == 0) {
            $fp = @fopen($to . $header['filename'], 'wb');
            IF (!$fp)
                Return(-1);
            $size = $header['compressed_size'];

            While ($size != 0) {
                $read_size = ($size < 2048 ? $size : 2048);
                $buffer = fread($zip, $read_size);
                $binary_data = pack('a' . $read_size, $buffer);
                @fwrite($fp, $binary_data, $read_size);
                $size -= $read_size;
            }
            fclose($fp);
            touch($to . $header['filename'], $header['mtime']);
        } Else {
            $fp = @fopen($to . $header['filename'] . '.gz', 'wb');
            IF (!$fp)
                Return(-1);
            $binary_data = pack('va1a1Va1a1', 0x8b1f, Chr($header['compression']), Chr(0x00), time(), Chr(0x00), Chr(3));

            fwrite($fp, $binary_data, 10);
            $size = $header['compressed_size'];

            While ($size != 0) {
                $read_size = ($size < 1024 ? $size : 1024);
                $buffer = fread($zip, $read_size);
                $binary_data = pack('a' . $read_size, $buffer);
                @fwrite($fp, $binary_data, $read_size);
                $size -= $read_size;
            }

            $binary_data = pack('VV', $header['crc'], $header['size']);
            fwrite($fp, $binary_data, 8);
            fclose($fp);

            $gzp = @gzopen($to . $header['filename'] . '.gz', 'rb') or die("Cette archive est compress閑");
            IF (!$gzp)
                Return(-2);
            $fp = @fopen($to . $header['filename'], 'wb');
            IF (!$fp)
                Return(-1);
            $size = $header['size'];

            While ($size != 0) {
                $read_size = ($size < 2048 ? $size : 2048);
                $buffer = gzread($gzp, $read_size);
                $binary_data = pack('a' . $read_size, $buffer);
                @fwrite($fp, $binary_data, $read_size);
                $size -= $read_size;
            }
            fclose($fp);
            gzclose($gzp);

            touch($to . $header['filename'], $header['mtime']);
            @unlink($to . $header['filename'] . '.gz');
        }
    }
    Return true;
}

}

$PHPZip = new PHPZip();
$zip_dir = "gd"; // 待压缩目录
$PHPZip->ZipDir($zip_dir, "1.zip", 2); // 文件夹打包 第三个参数1为直接下载,2为保存到服务器
$zip_files = array("1.php", "2.php"); // 待压缩文件
$PHPZip->ZipFile($zip_files, "2.zip", 2); // 多个文件批量压缩打包 第三个参数1为直接下载,2为保存到服务器
$PHPZip->Unzip_File("1.zip", "uploads"); // 参数一:解压的压缩包,参数二:解压到
$lists = get_List("1.zip"); // 获取压缩包文件列表

织梦dedeCMS让{dede:list}标签支持weight权重排序

修改\include\arc.listview.class.php在文件第727行处添加按weight排序判断代码:

else if($orderby=="weight") {
    $ordersql = "ORDER BY arc.weight $orderWay";
}

第778行处找到此段代码(如果不用默认的sortrank或id排序,使用联合查询(数据量大时非常缓慢)):
if(preg_match('/hot|click|lastpost|weight/', $orderby))

标签调用:
{dede:list isweight='Y' orderby='weight' orderway='asc'}

Linux如何查找大文件或目录总结

在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件夹的方法。

- 阅读剩余部分 -

Flex 布局基础

Flex是Flexible Box的缩写,意为"弹性布局",用来为盒状模型提供最大的灵活性。任何一个容器都可以指定为Flex布局。Webkit内核的浏览器,必须加上-webkit前缀。

bg2015071003.jpg

- 阅读剩余部分 -

织梦dedecms循环判断是否为第一个

判断是否为第一个
dedecms的arclist循环中,判断如果是第一个li,则添加固定的css,否则不加。

{dede:arclist row=4  flag='p'}
 <li [field:global name=autoindex runphp="yes"](@me==1)? @me="class=on":@me="";[/field:global]>[field:global.autoindex/]</li>
{/dede:arclist}

- 阅读剩余部分 -

dedecms织梦手机网站添加上一页/下一页的翻页功能

修改文件include/arc.archives.class.php文件,function GetPreNext($gtype='')函数修改为:

function GetPreNext($gtype='')
    {
        $rs = '';
        if(count($this->PreNext)<2)
        {
            $aid = $this->ArcID;
            $preR =  $this->dsql->GetOne("Select id From `#@__arctiny` where id<$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id desc");
            $nextR = $this->dsql->GetOne("Select id From `#@__arctiny` where id>$aid And arcrank>-1 And typeid='{$this->Fields['typeid']}' order by id asc");
            $next = (is_array($nextR) ? " where arc.id={$nextR['id']} " : ' where 1>2 ');
            $pre = (is_array($preR) ? " where arc.id={$preR['id']} " : ' where 1>2 ');
            $query = "Select arc.id,arc.title,arc.shorttitle,arc.typeid,arc.ismake,arc.senddate,arc.arcrank,arc.money,arc.filename,arc.litpic,
                        t.typedir,t.typename,t.namerule,t.namerule2,t.ispart,t.moresite,t.siteurl,t.sitepath
                        from `#@__archives` arc left join #@__arctype t on arc.typeid=t.id  ";
            $nextRow = $this->dsql->GetOne($query.$next);
            $preRow = $this->dsql->GetOne($query.$pre);
            
            
            
    
            if(is_array($preRow))
            {
                $mlink = GetFileUrl($preRow['id'],$preRow['typeid'],$preRow['senddate'],$preRow['title'],$preRow['ismake'],$preRow['arcrank'],
                $preRow['namerule'],$preRow['typedir'],$preRow['money'],$preRow['filename'],$preRow['moresite'],$preRow['siteurl'],$preRow['sitepath']);
                $mobile_mlink = "/m/view.php?aid=".$preRow['id'];
                $this->PreNext['pre'] = "上一篇:<a href='$mlink'>{$preRow['title']}</a> ";
                $this->PreNext['mobile_pre'] = "上一篇:<a href='$mobile_mlink'>{$preRow['title']}</a> ";
                $this->PreNext['preimg'] = "<a href='$mlink'><img src=\"{$preRow['litpic']}\" alt=\"{$preRow['title']}\"/></a> "; 
            }
            else
            {
                $this->PreNext['pre'] = "上一篇:没有了 ";
                $this->PreNext['mobile_pre'] = "上一篇:没有了 ";
                $this->PreNext['preimg'] ="<img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有上一图集了!\"/>";
            }
            if(is_array($nextRow))
            {
                $mlink = GetFileUrl($nextRow['id'],$nextRow['typeid'],$nextRow['senddate'],$nextRow['title'],$nextRow['ismake'],$nextRow['arcrank'],
                $nextRow['namerule'],$nextRow['typedir'],$nextRow['money'],$nextRow['filename'],$nextRow['moresite'],$nextRow['siteurl'],$nextRow['sitepath']);                
                $mobile_mlink = "/m/view.php?aid=".$nextRow['id'];
                $this->PreNext['next'] = "下一篇:<a href='$mlink'>{$nextRow['title']}</a> ";
                $this->PreNext['mobile_next'] = "下一篇:<a href='$mobile_mlink'>{$nextRow['title']}</a> ";
                $this->PreNext['nextimg'] = "<a href='$mlink'><img src=\"{$nextRow['litpic']}\" alt=\"{$nextRow['title']}\"/></a> ";
            }
            else
            {
                $this->PreNext['next'] = "下一篇:没有了 ";
                $this->PreNext['mobile_next'] = "下一篇:没有了 ";
                $this->PreNext['nextimg'] ="<a href='javascript:void(0)' alt=\"\"><img src=\"/templets/default/images/nophoto.jpg\" alt=\"对不起,没有下一图集了!\"/></a>";
            }
        }
        if($gtype=='pre')
        {
            $rs =  $this->PreNext['pre'];
        }
        else if($gtype=='preimg'){
            
            $rs =  $this->PreNext['preimg'];
        }        
        else if($gtype=='mobile_pre'){
            
            $rs =  $this->PreNext['mobile_pre'];
        }
        else if($gtype=='next')
        {
            $rs =  $this->PreNext['next'];
        }        
        else if($gtype=='mobile_next')
        {
            $rs =  $this->PreNext['mobile_next'];
        }
        else if($gtype=='nextimg'){
            
            $rs =  $this->PreNext['nextimg'];
        }
        else
        {
            $rs =  $this->PreNext['pre']." &nbsp; ".$this->PreNext['next'];
        }
        return $rs;
    }

在手机网站详情页模板内,将调用上一页、下一页标签插入。

  • {dede:prenext get='mobile_pre'/}
  • <div style="clear:both;"></div>
  • {dede:prenext get='mobile_next'/}