利用imagestring函数做的验证码,代码如下:
<?PHP
session_start();
session_register('SafeCode');
$type = 'gif';
$width= 100;
$height= 30;
header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = randStr(4,"");
if($type!='gif' && function_exists('imagecreatetruecolor')){
$im = @imagecreatetruecolor($width,$height);
}else{
$im = @imagecreate($width,$height);
}
$r = Array(225,211,255,223);
$g = Array(225,236,237,215);
$b = Array(225,236,166,125);
$key = rand(0,3);
$backColor = ImageColorAllocate($im,$r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置
$stringColor = ImageColorAllocate($im, 255,51,153);
for($i=0;$i<=100;$i++){
$pointX = rand(2,$width-2);
$pointY = rand(2,$height-2);
@imagesetpixel($im, $pointX, $pointY, $pointColor);
}
@imagestring($im, 5, 5, 1, $randval, $stringColor);
$ImageFun='Image'.$type;
$ImageFun($im);
@ImageDestroy($im);
$_SESSION['SafeCode'] = $randval;
//产生随机字符串
function randStr($len=6,$format='ALL') {
switch($format) {
case 'ALL':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break;
case 'CHAR':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break;
case 'NUMBER':
$chars='0123456789'; break;
default :
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
break;
}
$string="";
while(strlen($string)<$len)
$string.=substr($chars,(mt_rand()%strlen($chars)),1);
return $string;
}
?>
演示:http://jed.dzhope.com/aa.php
利用imagettftext() 做的验证码
<?PHP
session_start();
session_register('SafeCode');
$type = 'gif';
$width= 80;
$height= 30;
header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = randStr(4,"");
if($type!='gif' && function_exists('imagecreatetruecolor')){
$im = @imagecreatetruecolor($width,$height);
}else{
$im = @imagecreate($width,$height);
}
$r = Array(225,211,255,223);
$g = Array(225,236,237,215);
$b = Array(225,236,166,125);
$key = rand(0,3);
$backColor = ImageColorAllocate($im,$r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置
$stringColor = ImageColorAllocate($im, 255,51,153);
for($i=0;$i<=100;$i++){
$pointX = rand(2,$width-2);
$pointY = rand(2,$height-2);
@imagesetpixel($im, $pointX, $pointY, $pointColor);
}
///@imagestring($im, 5, 5, 1, $randval, $stringColor);
//////////////////////////////////////////
$font = "SIMHEI.TTF";
imagettftext($im, 20, 0, 10, 25, $stringColor, $font, $randval);
//////////////////////////////////////
$ImageFun='Image'.$type;
$ImageFun($im);
@ImageDestroy($im);
$_SESSION['SafeCode'] = $randval;
//产生随机字符串
function randStr($len=6,$format='ALL') {
switch($format) {
case 'ALL':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break;
case 'CHAR':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break;
case 'NUMBER':
$chars='0123456789'; break;
default :
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
break;
}
$string="";
while(strlen($string)<$len)
$string.=substr($chars,(mt_rand()%strlen($chars)),1);
return $string;
}
?>
演示:http://jed.dzhope.com/a.php这个在windows平台下实验通过,linux没有通过。但是肯定是可以用的。
验证码的使用
<img src=a.php align=absmiddle onclick="this.src='a.php?nocache='+Math.random()" style="cursor:hand"/>
验证码可刷新
<?PHP
session_start();
session_register('SafeCode');
$type = 'gif';
$width= 100;
$height= 30;
header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = randStr(4,"");
if($type!='gif' && function_exists('imagecreatetruecolor')){
$im = @imagecreatetruecolor($width,$height);
}else{
$im = @imagecreate($width,$height);
}
$r = Array(225,211,255,223);
$g = Array(225,236,237,215);
$b = Array(225,236,166,125);
$key = rand(0,3);
$backColor = ImageColorAllocate($im,$r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置
$stringColor = ImageColorAllocate($im, 255,51,153);
for($i=0;$i<=100;$i++){
$pointX = rand(2,$width-2);
$pointY = rand(2,$height-2);
@imagesetpixel($im, $pointX, $pointY, $pointColor);
}
@imagestring($im, 5, 5, 1, $randval, $stringColor);
$ImageFun='Image'.$type;
$ImageFun($im);
@ImageDestroy($im);
$_SESSION['SafeCode'] = $randval;
//产生随机字符串
function randStr($len=6,$format='ALL') {
switch($format) {
case 'ALL':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break;
case 'CHAR':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break;
case 'NUMBER':
$chars='0123456789'; break;
default :
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
break;
}
$string="";
while(strlen($string)<$len)
$string.=substr($chars,(mt_rand()%strlen($chars)),1);
return $string;
}
?>
演示:http://jed.dzhope.com/aa.php
利用imagettftext() 做的验证码
<?PHP
session_start();
session_register('SafeCode');
$type = 'gif';
$width= 80;
$height= 30;
header("Content-type: image/".$type);
srand((double)microtime()*1000000);
$randval = randStr(4,"");
if($type!='gif' && function_exists('imagecreatetruecolor')){
$im = @imagecreatetruecolor($width,$height);
}else{
$im = @imagecreate($width,$height);
}
$r = Array(225,211,255,223);
$g = Array(225,236,237,215);
$b = Array(225,236,166,125);
$key = rand(0,3);
$backColor = ImageColorAllocate($im,$r[$key],$g[$key],$b[$key]);//背景色(随机)
$borderColor = ImageColorAllocate($im, 0, 0, 0);//边框色
$pointColor = ImageColorAllocate($im, 255, 170, 255);//点颜色
@imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);//背景位置
@imagerectangle($im, 0, 0, $width-1, $height-1, $borderColor); //边框位置
$stringColor = ImageColorAllocate($im, 255,51,153);
for($i=0;$i<=100;$i++){
$pointX = rand(2,$width-2);
$pointY = rand(2,$height-2);
@imagesetpixel($im, $pointX, $pointY, $pointColor);
}
///@imagestring($im, 5, 5, 1, $randval, $stringColor);
//////////////////////////////////////////
$font = "SIMHEI.TTF";
imagettftext($im, 20, 0, 10, 25, $stringColor, $font, $randval);
//////////////////////////////////////
$ImageFun='Image'.$type;
$ImageFun($im);
@ImageDestroy($im);
$_SESSION['SafeCode'] = $randval;
//产生随机字符串
function randStr($len=6,$format='ALL') {
switch($format) {
case 'ALL':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; break;
case 'CHAR':
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break;
case 'NUMBER':
$chars='0123456789'; break;
default :
$chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
break;
}
$string="";
while(strlen($string)<$len)
$string.=substr($chars,(mt_rand()%strlen($chars)),1);
return $string;
}
?>
演示:http://jed.dzhope.com/a.php这个在windows平台下实验通过,linux没有通过。但是肯定是可以用的。
验证码的使用
<img src=a.php align=absmiddle onclick="this.src='a.php?nocache='+Math.random()" style="cursor:hand"/>
验证码可刷新
IE5.5开始支持浮动框架的内容透明。如果想要为浮动框架定义透明内容,则必须满足下列条件。
1.与 iframe 元素一起使用的 allowTransparency 标签属性必须设置为 true。
2.在 iframe 内容源文档,background-color 或 body 元素的 bgColor 标签属性必须设置为 transparent。
具体步骤:
1. 包含框架页的代码。
<body bgColor="#eeeeee">
<iframe allowTransparency="true" src="transparent.htm">
</iframe>
2.transparent.htm页的代码。
<body bgColor="transparent">
透明的iframe文档
1.与 iframe 元素一起使用的 allowTransparency 标签属性必须设置为 true。
2.在 iframe 内容源文档,background-color 或 body 元素的 bgColor 标签属性必须设置为 transparent。
具体步骤:
1. 包含框架页的代码。
<body bgColor="#eeeeee">
<iframe allowTransparency="true" src="transparent.htm">
</iframe>
2.transparent.htm页的代码。
<body bgColor="transparent">
透明的iframe文档
IE5.5开始支持浮动框架的内容透明。如果想要为浮动框架定义透明内容,则必须满足下列条件。
1.与 iframe 元素一起使用的 allowTransparency 标签属性必须设置为 true。
2.在 iframe 内容源文档,background-color 或 body 元素的 bgColor 标签属性必须设置为 transparent。
具体步骤:
1. 包含框架页的代码。
<body bgColor="#eeeeee">
<iframe allowTransparency="true" src="transparent.htm">
</iframe>
2.transparent.htm页的代码。
透明的iframe文档
1.与 iframe 元素一起使用的 allowTransparency 标签属性必须设置为 true。
2.在 iframe 内容源文档,background-color 或 body 元素的 bgColor 标签属性必须设置为 transparent。
具体步骤:
1. 包含框架页的代码。
<body bgColor="#eeeeee">
<iframe allowTransparency="true" src="transparent.htm">
</iframe>
2.transparent.htm页的代码。
透明的iframe文档
FCKeditor2.3.2在线编辑器非常好用,完全支持文件上传。今天baidu了一下午终于搞定了。 下载FCKeditor2.3.2,解压至FCKeditor。
1首先删除不必要的文件节省空间。凡是以_开头的文件如_samples,_testcases和一些用不到的.asp、.jsp、.cfm文件统统干掉。
2修改fckconfig.js
FCKConfig.AutoDetectLanguage = true ;//是否自动检测语言
FCKConfig.DefaultLanguage = 'zh-cn' ;//设置语言
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;//设置皮肤
FCKConfig.TabSpaces = 1 ;//tab是否有效
FCKConfig.ToolbarStartExpanded = true ;//编辑工具条是否出现,等点“展开工具栏”时才出现
FCKConfig.FontNames = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;//添加中文字体
修改FCKeditor\editor\CSS\fck_editorarea.css
设置默认字体及大小
body, td
{
font-family: Arial, Verdana, Sans-Serif;
font-size: 14px;
}
3关于文件上传的设置
修改fckconfig.js
var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | php
修改fckeditor\editor\filemanager\browser\default\connectors\php\config.php
$Config['Enabled'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' ;//设置上传的文件夹,可自己指定
修改fckeditor\editor\filemanager\upload\php\config.php
$Config['Enabled'] = true ;
$Config['UseFileType'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' ;//同上要一样
4引入在线编辑器时只需
include("fckeditor/fckeditor.php") ;
$oFCKeditor = new FCKeditor('FCKeditor1') ;//实例化
$oFCKeditor->BasePath = 'fckeditor/';//这个路径一定要和上面那个引入路径一致,否则会报错:找不到fckeditor.html页面
//$oFCKeditor->Value = '' ;
$oFCKeditor->Width = '100%' ;
$oFCKeditor->Height = '300' ;
$oFCKeditor->Create() ;
?>
JS用alert( FCKeditorAPI.GetInstance('FCKeditor1').GetXHTML( true ))得到FCKeditor1的值;
PHP用$_POST['FCKeditor1']得到FCKeditor1的值。
1首先删除不必要的文件节省空间。凡是以_开头的文件如_samples,_testcases和一些用不到的.asp、.jsp、.cfm文件统统干掉。
2修改fckconfig.js
FCKConfig.AutoDetectLanguage = true ;//是否自动检测语言
FCKConfig.DefaultLanguage = 'zh-cn' ;//设置语言
FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/default/' ;//设置皮肤
FCKConfig.TabSpaces = 1 ;//tab是否有效
FCKConfig.ToolbarStartExpanded = true ;//编辑工具条是否出现,等点“展开工具栏”时才出现
FCKConfig.FontNames = '宋体;黑体;隶书;楷体_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;//添加中文字体
修改FCKeditor\editor\CSS\fck_editorarea.css
设置默认字体及大小
body, td
{
font-family: Arial, Verdana, Sans-Serif;
font-size: 14px;
}
3关于文件上传的设置
修改fckconfig.js
var _FileBrowserLanguage = 'php' ; // asp | aspx | cfm | lasso | perl | php
var _QuickUploadLanguage = 'php' ; // asp | aspx | cfm | lasso | php
修改fckeditor\editor\filemanager\browser\default\connectors\php\config.php
$Config['Enabled'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' ;//设置上传的文件夹,可自己指定
修改fckeditor\editor\filemanager\upload\php\config.php
$Config['Enabled'] = true ;
$Config['UseFileType'] = true ;
$Config['UserFilesPath'] = '/UserFiles/' ;//同上要一样
4引入在线编辑器时只需
include("fckeditor/fckeditor.php") ;
$oFCKeditor = new FCKeditor('FCKeditor1') ;//实例化
$oFCKeditor->BasePath = 'fckeditor/';//这个路径一定要和上面那个引入路径一致,否则会报错:找不到fckeditor.html页面
//$oFCKeditor->Value = '' ;
$oFCKeditor->Width = '100%' ;
$oFCKeditor->Height = '300' ;
$oFCKeditor->Create() ;
?>
JS用alert( FCKeditorAPI.GetInstance('FCKeditor1').GetXHTML( true ))得到FCKeditor1的值;
PHP用$_POST['FCKeditor1']得到FCKeditor1的值。
PHP提供两个办法来将Unix的时间戳值转换成为有用的数据。第一个是date()函数。这个函数有两个参数-第一个字符串用于设定你所希望返回的格式,第二个为Unix的时间戳值。
格式化字符串通过一些简单的特殊格式化字符来显示你所希望看到的格式的日期和时间。假设你希望日期以这样的格式显示“18h01 Sunday 21 May”。
我们需要对字符串中的每一部分使用一个特殊格式化字符,你可以从PHP手册中日期和时间函数库中找到。这样的特殊格式化字符数量不少,他们所表示的类似于星期几、月的英文名、用2位或4位数表示的年份,是否是上午(AM)或下午(PM)以及其他。对于这个例子我们需要的特殊字符为:
‘H’ -24 小时制的小时
‘i’- 分钟
‘l’- 星期几的英文全名
‘d’- 本月的第几日
‘F’- 月份的英文全名
因此我们的格式化字符串为”Hhi l d F”, PHP代码为:
?
echo date ("Hhi l d F" ,time());
?
当我们执行这段代码,我们发现我们所得到的结果为:
180609 Sunday 21 May
这样的结果看起来有些奇怪。让我们再查一下PHP手册,原来’h’所代表的是12 小时制的小时数。这再次证明了一句真理:“计算机只做你所告诉它该做的,而不是你想要它做的”。我们有两个选择。第一个是在h前使用转义字符“”:
echo date ("Hhi l d F", time());
我们得到这样的结果:
18h12 Sunday 21 May
这正是我们所要的。但如果我们在一个十分复杂的句子中需要包含日期和时间,我们是否需要对每个字符使用转义字符?
答案当然是不。我们使用另一个函数strftime()。
strftime()有两个好处。第一个好处我们并不在本文讨论范围内-如果你使用setlocale()函数,你可以通过strftime得到相应语言的月份的名称。另外的一个好处是你可以将特别的日期和时间的格式化字符包含在你的字符串中。这同时也意味着无论你是否要学习date()函数的所有特殊格式化字符,你都必须学习一整套完全不同的格式化字符。
strftime()工作的方式和date()没有什么不同,除了特殊格式化字符的前面必须添加一个百分号%。如果用strftime()函数,前面例子的代码如下:
<?
echo strftime ("%Hh%M %A %d %b" ,time());
?>
结果为:
18h24 Sunday 21 May
这也许看起来将简化繁,但考虑一下如果你所需要的显示的为"Today is Sunday 21 May 2000. The time is somewhere close to 18h24." 我想使用date()函数无疑令人感到厌烦。
在开始的时候,我提及我们有两种方式可以从Unix时间戳值中得到有用的数据。我们刚刚了解了date()和strftime()。另一个getdate()。这个函数只需要Unix 的时间戳值作为参数,而函数的返回值为日期和时间的数组。
下面是一个例子:
<?
$date_time_array = getdate (time());
echo $date_time_array[ "weekday"];
?>
返回的结果为:
Sunday
除了"weekday",该数组的其他部分为:
"seconds" –秒
"minutes" –分
"hours" –小时
“mday" - 本月的第几天
"wday" -本周的第几天(数字)
"mon" -月(数字)
"year" –年
"yday" - r本年的第几天(数字)
"month" -月份全名
格式化字符串通过一些简单的特殊格式化字符来显示你所希望看到的格式的日期和时间。假设你希望日期以这样的格式显示“18h01 Sunday 21 May”。
我们需要对字符串中的每一部分使用一个特殊格式化字符,你可以从PHP手册中日期和时间函数库中找到。这样的特殊格式化字符数量不少,他们所表示的类似于星期几、月的英文名、用2位或4位数表示的年份,是否是上午(AM)或下午(PM)以及其他。对于这个例子我们需要的特殊字符为:
‘H’ -24 小时制的小时
‘i’- 分钟
‘l’- 星期几的英文全名
‘d’- 本月的第几日
‘F’- 月份的英文全名
因此我们的格式化字符串为”Hhi l d F”, PHP代码为:
?
echo date ("Hhi l d F" ,time());
?
当我们执行这段代码,我们发现我们所得到的结果为:
180609 Sunday 21 May
这样的结果看起来有些奇怪。让我们再查一下PHP手册,原来’h’所代表的是12 小时制的小时数。这再次证明了一句真理:“计算机只做你所告诉它该做的,而不是你想要它做的”。我们有两个选择。第一个是在h前使用转义字符“”:
echo date ("Hhi l d F", time());
我们得到这样的结果:
18h12 Sunday 21 May
这正是我们所要的。但如果我们在一个十分复杂的句子中需要包含日期和时间,我们是否需要对每个字符使用转义字符?
答案当然是不。我们使用另一个函数strftime()。
strftime()有两个好处。第一个好处我们并不在本文讨论范围内-如果你使用setlocale()函数,你可以通过strftime得到相应语言的月份的名称。另外的一个好处是你可以将特别的日期和时间的格式化字符包含在你的字符串中。这同时也意味着无论你是否要学习date()函数的所有特殊格式化字符,你都必须学习一整套完全不同的格式化字符。
strftime()工作的方式和date()没有什么不同,除了特殊格式化字符的前面必须添加一个百分号%。如果用strftime()函数,前面例子的代码如下:
<?
echo strftime ("%Hh%M %A %d %b" ,time());
?>
结果为:
18h24 Sunday 21 May
这也许看起来将简化繁,但考虑一下如果你所需要的显示的为"Today is Sunday 21 May 2000. The time is somewhere close to 18h24." 我想使用date()函数无疑令人感到厌烦。
在开始的时候,我提及我们有两种方式可以从Unix时间戳值中得到有用的数据。我们刚刚了解了date()和strftime()。另一个getdate()。这个函数只需要Unix 的时间戳值作为参数,而函数的返回值为日期和时间的数组。
下面是一个例子:
<?
$date_time_array = getdate (time());
echo $date_time_array[ "weekday"];
?>
返回的结果为:
Sunday
除了"weekday",该数组的其他部分为:
"seconds" –秒
"minutes" –分
"hours" –小时
“mday" - 本月的第几天
"wday" -本周的第几天(数字)
"mon" -月(数字)
"year" –年
"yday" - r本年的第几天(数字)
"month" -月份全名
在你的程序初始化时使用如下代码:
<?php
$Php2Html_FileUrl = $_SERVER["REQUEST_URI"];
$Php2Html_UrlString = str_replace("/", "", strrchr($Php2Html_FileUrl, "/"));
$Php2Html_UrlQueryStrList = explode("@", $Php2Html_UrlString);
foreach($Php2Html_UrlQueryStrList as $Php2Html_UrlQueryStr)
{
$Php2Html_TmpArray = explode("|", $Php2Html_UrlQueryStr);
$_GET[$Php2Html_TmpArray[0]] = $Php2Html_TmpArray[1];
}
echo '假静态:$_GET变量<br />';
print_r($_GET);
?>
然后p
hp中调用$_GET变量就像平常一样了。
连接使用方式:
****.php/param1|1234@param2|4321
和****.php?param1=1234¶m2=4321一样。
<?php
$Php2Html_FileUrl = $_SERVER["REQUEST_URI"];
$Php2Html_UrlString = str_replace("/", "", strrchr($Php2Html_FileUrl, "/"));
$Php2Html_UrlQueryStrList = explode("@", $Php2Html_UrlString);
foreach($Php2Html_UrlQueryStrList as $Php2Html_UrlQueryStr)
{
$Php2Html_TmpArray = explode("|", $Php2Html_UrlQueryStr);
$_GET[$Php2Html_TmpArray[0]] = $Php2Html_TmpArray[1];
}
echo '假静态:$_GET变量<br />';
print_r($_GET);
?>
然后p
hp中调用$_GET变量就像平常一样了。
连接使用方式:
****.php/param1|1234@param2|4321
和****.php?param1=1234¶m2=4321一样。
大家都知道,rename()函数可以对文件或目录进行重命名的操作。其实它还可以做很多事情。
熟悉unix的朋友应该知道shell命令mv,它相当与win32的移动,而且移动的同时可进行重命名。我发现,php的rename()函数就相当于mv,它不仅仅只有简单的重命名的功能,同样可以改变文件甚至整个目录的路径。
例如:
$oldpath ----文件或目录原来路径
$newpath ----新定义路径
那么 rename($oldpath,$newpath)就可以完成文件/目录移动的操作
经过我的测试,win32和unix的php4版本都支持这个功能。
另外,好象php4的win32版取消了unlink()函数。那么还可以巧用rename()函数来完成删除的操作,例如:
$path ---- 文件或目录路径
$tmp ---- tmp目录(/tmp)
用rename($path,$tmp) 将文件移动到tmp目录.
熟悉unix的朋友应该知道shell命令mv,它相当与win32的移动,而且移动的同时可进行重命名。我发现,php的rename()函数就相当于mv,它不仅仅只有简单的重命名的功能,同样可以改变文件甚至整个目录的路径。
例如:
$oldpath ----文件或目录原来路径
$newpath ----新定义路径
那么 rename($oldpath,$newpath)就可以完成文件/目录移动的操作
经过我的测试,win32和unix的php4版本都支持这个功能。
另外,好象php4的win32版取消了unlink()函数。那么还可以巧用rename()函数来完成删除的操作,例如:
$path ---- 文件或目录路径
$tmp ---- tmp目录(/tmp)
用rename($path,$tmp) 将文件移动到tmp目录.
is_file 测试文件是否为正常文件。
语法: boolean is_file(string filename);
返回值: 布尔值
函数种类: 文件存取
内容说明: 本函数返回 true 值则表示指定的 filename 存在并为正常的文件。返回值放在快取缓冲区中,可以参考 clearstatcache()。
参考: is_dir() is_link()
is_link 测试文件是否为链接文件。
语法: boolean is_link(string filename);
返回值: 布尔值
函数种类: 文件存取
内容说明: 本函数返回 true 值则表示指定的 filename 存在并为符号链接文件 (symbolic link)。返回值放在快取缓冲区中,可以参考 clearstatcache()。
参考: is_dir() is_file()
is_readable 测试文件是否可读取。
语法: boolean is_readable(string filename);
返回值: 布尔值
函数种类: 文件存取
内容说明: 本函数返回 true 值则表示指定的 filename 存在并且可读取。返回值放在快取缓冲区中,参考 clearstatcache()。
参考: is_writeable()
语法: boolean is_file(string filename);
返回值: 布尔值
函数种类: 文件存取
内容说明: 本函数返回 true 值则表示指定的 filename 存在并为正常的文件。返回值放在快取缓冲区中,可以参考 clearstatcache()。
参考: is_dir() is_link()
is_link 测试文件是否为链接文件。
语法: boolean is_link(string filename);
返回值: 布尔值
函数种类: 文件存取
内容说明: 本函数返回 true 值则表示指定的 filename 存在并为符号链接文件 (symbolic link)。返回值放在快取缓冲区中,可以参考 clearstatcache()。
参考: is_dir() is_file()
is_readable 测试文件是否可读取。
语法: boolean is_readable(string filename);
返回值: 布尔值
函数种类: 文件存取
内容说明: 本函数返回 true 值则表示指定的 filename 存在并且可读取。返回值放在快取缓冲区中,参考 clearstatcache()。
参考: is_writeable()
fgets 取得文件指针所指的行。
语法: string fgets(int fp, int length);
返回值: 字符串
函数种类: 文件存取
内容说明: 本函数取得文件指针所指的行,返回字符串长度为行的长度减一。若发生错误则返回 false。一般常遇到的陷阱是用 C 语言的经验来使用本函数,而 EOF 时的处理方式则和 C 语言的 fgets() 不同。其中的文件指针必须是有效的,且必须是已经用 fopen()、popen() 或 fsockopen() 成功开文件的指针。
使用范例
<?php
$fd = fopen("/tmp/myfile.txt", "r");
while ($buffer = fgets($fd, 4096)) {
echo $buffer;
}
fclose($fd);
?>
语法: string fgets(int fp, int length);
返回值: 字符串
函数种类: 文件存取
内容说明: 本函数取得文件指针所指的行,返回字符串长度为行的长度减一。若发生错误则返回 false。一般常遇到的陷阱是用 C 语言的经验来使用本函数,而 EOF 时的处理方式则和 C 语言的 fgets() 不同。其中的文件指针必须是有效的,且必须是已经用 fopen()、popen() 或 fsockopen() 成功开文件的指针。
使用范例
<?php
$fd = fopen("/tmp/myfile.txt", "r");
while ($buffer = fgets($fd, 4096)) {
echo $buffer;
}
fclose($fd);
?>
basename: 返回不含路径的文件字符串。
chgrp: 改变文件所属的群组。
chmod: 改变文件的属性。
chown: 改变文件的拥有者。
clearstatcache: 清除文件状态快取。
copy: 复制文件。
delete: 无用的项目。
dirname: 取得路径中的目录名。
diskfreespace: 取得目录所在的剩余可用空间。
fclose: 关闭已打开的文件。
feof: 测试文件指针是否指到档尾。
fgetc: 取得文件指针所指的字符。
fgetcsv: 取得文件指针所指行,并解析 CSV 字段。
fgets: 取得文件指针所指的行。
fgetss: 取得文件指针所指的行,并去掉 HTML 语言标记。
file: 将文件全部读入数组变量中。
file_exists: 检查文件是否存在。
fileatime: 取得文件最后的存取时间。
filectime: 取得文件最后的改变时间。
filegroup: 取得文件所属的群组。
fileinode: 取得文件的 inode 值。
filemtime: 取得文件最后的修改时间。
fileowner: 取得文件的拥有者。
fileperms: 取得文件的权限配置。
filesize: 获得文件的大小。
filetype: 获得文件的类型。
flock: 锁住文件。
chgrp: 改变文件所属的群组。
chmod: 改变文件的属性。
chown: 改变文件的拥有者。
clearstatcache: 清除文件状态快取。
copy: 复制文件。
delete: 无用的项目。
dirname: 取得路径中的目录名。
diskfreespace: 取得目录所在的剩余可用空间。
fclose: 关闭已打开的文件。
feof: 测试文件指针是否指到档尾。
fgetc: 取得文件指针所指的字符。
fgetcsv: 取得文件指针所指行,并解析 CSV 字段。
fgets: 取得文件指针所指的行。
fgetss: 取得文件指针所指的行,并去掉 HTML 语言标记。
file: 将文件全部读入数组变量中。
file_exists: 检查文件是否存在。
fileatime: 取得文件最后的存取时间。
filectime: 取得文件最后的改变时间。
filegroup: 取得文件所属的群组。
fileinode: 取得文件的 inode 值。
filemtime: 取得文件最后的修改时间。
fileowner: 取得文件的拥有者。
fileperms: 取得文件的权限配置。
filesize: 获得文件的大小。
filetype: 获得文件的类型。
flock: 锁住文件。