顺便说一下创建文件目录的代码
//创建类似"../../../xxx/xxx.txt"的目录
function createdirs($path, $mode = 0777) //mode 077
{
$dirs = explode('/',$path);
$pos = strrpos($path, ".");
if ($pos === false) { // note: three equal signs
// not found, means path ends in a dir not file
$subamount=0;
}
else {
$subamount=1;
}
for ($c=0;$c < count($dirs) - $subamount; $c++) {
$thispath="";
for ($cc=0; $cc <= $c; $cc++) {
$thispath.=$dirs[$cc].'/';
}
if (!file_exists($thispath)) {
//print "$thispath";
mkdir($thispath,$mode); //mkdir函数创建目录
}
}
}
//调用如createdirs("xxx/xxxx/xxxx",);
//原函数中使用$GLOBALS["dirseparator"]我改成了'/'
function recur_mkdirs($path, $mode = 0777) //mode 0777
{
//$GLOBALS["dirseparator"]
$dirs = explode($GLOBALS["dirseparator"],$path);
$pos = strrpos($path, ".");
if ($pos === false) { // note: three equal signs
// not found, means path ends in a dir not file
$subamount=0;
}
else {
$subamount=1;
}
这些只是一些基本的关于文件的操作代码,相信对初学者很有用,在此贴出来,希望有抛砖引玉之功能!







