要使目录/文件
if (!file_exists("parent_folder/$username")) {
//Create a file with read write execute PERMISSIONS ENABLED
//Please check : your parent folder also must have 0777 permissions to avoid any kind of read write error
mkdir("parent_folder/$username", 0777);
//now u have to create a FILE with .php
//now this file_put_contents is VERY importnant !
$pagename = $username ;
$newFileName = './parent_folder/$username/'.$pagename.".php";
$newFileContent = '<?php echo "something..."; ?>';
if (file_put_contents($newFileName, $newFileContent) !== false) {
//notify file is created
echo "File created (" . basename($newFileName) . ")";
} else {
//notify u have error
echo "Cannot create file (" . basename($newFileName) . ")";
}
//now create ur .php file in user folder
}
else {
echo "Your parent folder does not exist"
}
现在可能出现的错误和一些技巧
1)大多数人做的fopen(“filename_with_PATH”,“W”) 并期望文件将在路径文件夹中产生! 有些时候,它可能属于错误(取决于版本)
的fopen意味着您的PHP所在
2)检查乌尔PHP许可在php.ini创建的目录中的文件如果妳不给PHP写权限,远程访问则u可能会得到一些错误(它会显示,美在我的脚本错误)
3)欲了解更多信息和修补file_put_contents
希望这会对你有所帮助。
这与JavaScript或HTML有什么关系? – vlaz
为什么不将用户的详细信息保存在数据库中?稍后,您可以从数据库中检索* that *并根据您的逻辑显示/操作。 –
@RajdeepPaul我喜欢数据库 – meme