header("Content-type: text/html;charset=gb2312");
set_time_limit(0);
$fileName = "log/log.txt";
for($i=0;$i < 100;$i++ )
{
$data = "admin".$i." ".date("Y-m-d H:i:s")." 恭喜添加成功!\n";
if( writeLog( $fileName,$data ) )
{
echo "good\n";
}else{
echo "bad\n";
}
}
function writeLog($fileName,$data,$method="W")
{
$fp = fopen($fileName,$data,$method);
flock($fp,LOCK_EX); //如果文件不存在則創建文件
$fileData = fwrite($fp,$data);
if(!$fileData)
{
return FALSE;
}else{
return TRUE;
}
}
?>
header("Content-type: text/html;charset=gb2312");
/*
*@param string $path
*@return Boolean
*/
function makeDir($path)
{
if( empty($path) )
{
echo "路徑不能為空";
}
$dirs = array();
$path = preg_replace('/(\/){2,}|{\\\}{1,}/','/',$path);
$dirs = explode("/",$path);
$path ="";
foreach($dirs as $folder)
{
$path.=$folder."/";
if(!is_dir($path))
{
mkdir($path,0700) ;
}
}
if( is_dir($path) )
{
return TRUE;
}else{
return FALSE;
}
}
$mk = makeDir( 'test/test/sda/ete/eterer/*\//ere/ew/');
if( $mk )
{
echo "創建成功!";
}else{
echo "創建失敗!";
}
?>
header("Content-type: text/html;charset=gb2312");
function rmFile($path,$fileName)
{
$path = preg_replace('/(\/){2,}|{\\\}{1,}/','/',$path);
$path.= $fileName;
if(is_file($path))
{
unlink($path);
}else{
echo $path."路徑不存在!";
}
}
rmFile('test/test/sda/ete/eterer/ere/ew/','1.txt');
?>
















