无限极分类中最经典的代码(函数)
第一种形式(最新版本)推荐使用:<?php function d($arr,$pid,$s) { static $r_arr=array(); static $n = 0; $s=$s." "; for($i=0;$i<count($arr);$i++){ if($arr[$i]['parentid']==$pid){ $r_arr[$n]['catname'] = $s.'|-'.$arr[$i]['catname']; $r_arr[$n]['catid'] = $arr[$i]['catid']; $n++; for($j=0;$j<count($arr);$j++){ if($arr[$i]['catid']==$arr[$j]['parentid']){ $r_arr[$n]['catname'] = $s." |-".$arr[$j]['catname']; $r_arr[$n]['catid'] = $arr[$j]['catid']; $n++; d($arr,$arr[$j]['catid'],$s." "); } } } } return $r_arr; } ?>第二种形式(原始版本):
<?php header("Content-Type:text/html;charset=utf-8"); function d($arr,$pid,$s) { $s=$s." "; for($i=0;$i<count($arr);$i++){ if($arr[$i][2]==$pid){ echo $s.$arr[$i][1]."<br>"; for($j=0;$j<count($arr);$j++){ if($arr[$i][0]==$arr[$j][2]){ echo $s." ".$arr[$j][1]."<br>"; d($arr,$arr[$j][0],$s." "); } } } } } $arr1=array('a1','根目录1','0','1'); $arr2=array('b1','根目录2','0','1'); $arr3=array('a2','一级目录','a1','2'); $arr4=array('b2','一级目录','b1','2'); $arr5=array('a3','二级目录','a2','3'); $arr6=array('b3','二级目录','b2','3'); $arr7=array('a4','三级目录','a3','4'); $arr=array($arr1,$arr2,$arr3,$arr4,$arr5,$arr6,$arr7); d($arr,'0'," "); ?>
php 遍历目录以及子目录
源码如下:<?php $dir = "c:/wamp/www/test/"; //目录名称必须是这种格式 $space=""; function fun1($dir,$space="") { if(is_dir($dir) && $handle = opendir($dir)){ $space .= " "; while(false!== ($file = readdir($handle))){ if($file=="." || $file=="..") continue; if(is_dir($dir.$file.'/')){ echo "$space|-$file<br>"; fun1($dir.$file.'/',$space); }else echo "$space|-$file<br>"; } closedir($handle); }else{ echo "This have a error!"; } } fun1($dir); ?>遍历效果如下:
|-1.php
|-2.php
|-2010-05-22_101859.jpg
|-321.html
|-ci
|-.htaccess
|-index.php
|-system
本地apache虚拟主机的配置
第一步:在 C:\WINDOWS\system32\drivers\etc 下找到 hosts 文件 ,打开并且在最后加上127.0.0.1 localhost 127.0.0.1 uc.521-wf.com 127.0.0.1 uch.521-wf.com第二步:在apache 的配置文件 httpd.conf 的最后加上如下的代码:
NameVirtualHost 127.0.0.1 <VirtualHost 127.0.0.1:80> ServerAdmin admin@521-wf.com DocumentRoot c:/wamp/www/ ServerName localhost </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin admin@521-wf.com DocumentRoot c:/wamp/www/uc/ ServerName uc.521-wf.com </VirtualHost> <VirtualHost 127.0.0.1:80> ServerAdmin admin@521-wf.com DocumentRoot c:/wamp/www/uch/ ServerName uch.521-wf.com </VirtualHost>但是这是核心的代码,不是固定的写法:
ServerAdmin 你的邮件地址(不过可以随便写,这也只不过是虚拟环境而已)
DocumentRoot 这是你项目的路径
ServerName 这是你的虚拟域名
有时候你把上面的127.0.0.1 换为 * 也可以。但是有时候不行。我建议还是加上。
我习惯于使用 wamp 所以我并没有加在配置文件的最后面,而是加在了以下两行代码之前:
Include "c:/wamp/apache2/conf/alias/phpmyadmin.conf" Include "c:/wamp/apache2/conf/alias/sqlitemanager.conf"当然如果你的操作系统装在了d盘,或者是其他盘,那就看着办吧! 这个配置我在学校里面配置我好多次,不能说倒背如流,但是可以说是滚光烂熟了吧。但是到了公司,两个多月不用了,突然想装一下uchome ,配置了半天,老是出错 。所以 还是写在这儿,以防以后再忘了。 <<<<<<<<<<<<<<<<<<<<<<<<<<补充,还可以使用以下这种方式,更安全
<VirtualHost *:80> DocumentRoot "D:/wamp/www/framework/webroot" ServerName star #ServerAlias *.shop.com.cn ErrorLog "logs/starland.ifensi-error.log" CustomLog "logs/make.openqee.com.cn.log" common <Directory "D:/wamp/www/framework"> Options FollowSymLinks AllowOverride All Order deny,allow allow from all DirectoryIndex index.html index.php </Directory> </VirtualHost>
PHP Content-type 的说明
<?php $mimetypes = array( 'ez' => 'application/andrew-inset', 'hqx' => 'application/mac-binhex40', 'cpt' => 'application/mac-compactpro', 'doc' => 'application/msword', 'bin' => 'application/octet-stream', 'dms' => 'application/octet-stream', 'lha' => 'application/octet-stream', 'lzh' => 'application/octet-stream', 'exe' => 'application/octet-stream', 'class' => 'application/octet-stream', 'so' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', 'xls' => 'application/vnd.ms-excel', 'ppt' => 'application/vnd.ms-powerpoint', 'wbxml' => 'application/vnd.wap.wbxml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'bcpio' => 'application/x-bcpio', 'vcd' => 'application/x-cdlink', 'pgn' => 'application/x-chess-pgn', 'cpio' => 'application/x-cpio', 'csh' => 'application/x-csh', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'dxr' => 'application/x-director', 'dvi' => 'application/x-dvi', 'spl' => 'application/x-futuresplash', 'gtar' => 'application/x-gtar', 'hdf' => 'application/x-hdf', 'js' => 'application/x-javascript', 'skp' => 'application/x-koan', 'skd' => 'application/x-koan', 'skt' => 'application/x-koan', 'skm' => 'application/x-koan', 'latex' => 'application/x-latex', 'nc' => 'application/x-netcdf', 'cdf' => 'application/x-netcdf', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'swf' => 'application/x-shockwave-flash', 'sit' => 'application/x-stuffit', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'tar' => 'application/x-tar', 'tcl' => 'application/x-tcl', 'tex' => 'application/x-tex', 'texinfo' => 'application/x-texinfo', 'texi' => 'application/x-texinfo', 't' => 'application/x-troff', 'tr' => 'application/x-troff', 'roff' => 'application/x-troff', 'man' => 'application/x-troff-man', 'me' => 'application/x-troff-me', 'ms' => 'application/x-troff-ms', 'ustar' => 'application/x-ustar', 'src' => 'application/x-wais-source', 'xhtml' => 'application/xhtml+xml', 'xht' => 'application/xhtml+xml', 'zip' => 'application/zip', 'au' => 'audio/basic', 'snd' => 'audio/basic', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'kar' => 'audio/midi', 'mpga' => 'audio/mpeg', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'aif' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'm3u' => 'audio/x-mpegurl', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'ra' => 'audio/x-realaudio', 'wav' => 'audio/x-wav', 'pdb' => 'chemical/x-pdb', 'xyz' => 'chemical/x-xyz', 'bmp' => 'image/bmp', 'gif' => 'image/gif', 'ief' => 'image/ief', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpe' => 'image/jpeg', 'png' => 'image/png', 'tiff' => 'image/tiff', 'tif' => 'image/tiff', 'djvu' => 'image/vnd.djvu', 'djv' => 'image/vnd.djvu', 'wbmp' => 'image/vnd.wap.wbmp', 'ras' => 'image/x-cmu-raster', 'pnm' => 'image/x-portable-anymap', 'pbm' => 'image/x-portable-bitmap', 'pgm' => 'image/x-portable-graymap', 'ppm' => 'image/x-portable-pixmap', 'rgb' => 'image/x-rgb', 'xbm' => 'image/x-xbitmap', 'xpm' => 'image/x-xpixmap', 'xwd' => 'image/x-xwindowdump', 'igs' => 'model/iges', 'iges' => 'model/iges', 'msh' => 'model/mesh', 'mesh' => 'model/mesh', 'silo' => 'model/mesh', 'wrl' => 'model/vrml', 'vrml' => 'model/vrml', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'asc' => 'text/plain', 'txt' => 'text/plain', 'rtx' => 'text/richtext', 'rtf' => 'text/rtf', 'sgml' => 'text/sgml', 'sgm' => 'text/sgml', 'tsv' => 'text/tab-separated-values', 'wml' => 'text/vnd.wap.wml', 'wmls' => 'text/vnd.wap.wmlscript', 'etx' => 'text/x-setext', 'xsl' => 'text/xml', 'xml' => 'text/xml', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpe' => 'video/mpeg', 'qt' => 'video/quicktime', 'mov' => 'video/quicktime', 'mxu' => 'video/vnd.mpegurl', 'avi' => 'video/x-msvideo', 'movie' => 'video/x-sgi-movie', 'ice' => 'x-conference/x-cooltalk', ); ?>