创建文件夹
<?php
$username = "testjiang123";
$dir = "../mydir/".$username;
function createdir($dir) {
if (file_exists($dir) && is_dir($dir)) {} else {
mkdir($dir, 0777);
}
creat_file($dir);
}
?>创建文件
<?php
//创建文件
function creat_file($path) {
$sFile = "test.html";
$var_content = "文件内容";
if (file_exists($path."/".$sFile)){
creat_file();
} else {
$fp = fopen($path. "/".$sFile, "w");
fwrite($fp, $var_content);
fclose($fp);
}
return $sFile;
}
createdir($dir);
//此处还加了一个PHP的COPY函数,COPY当前目录下的mytest.php到刚才创建的目录下,并重新命名为目录名+_mytest.php
copy("mytest.php",$dir."/".$username."_mytest.php");
?>创建文件夹当前路径
$username="image";
$dir = __DIR__ . $username;
creat_file($dir);
function creat_file($dir)
{
//创建文件夹
if(file_exists($dir) && is_dir($dir)){
}else{
mkdir ($dir,0777);
}
}
爱笔记