[英]PHP user profile page
Im trying to make a website with users on it, and I'm trying to create a script so that whenever a new user registers it will automatically create a user folder and profile for them but when I try to register it doesn't create the files,我正在尝试创建一个包含用户的网站,并且我正在尝试创建一个脚本,以便每当新用户注册时,它都会自动为他们创建一个用户文件夹和配置文件,但是当我尝试注册时,它不会创建文件,
could someone please help me with this, Thanks有人可以帮我解决这个问题吗,谢谢
<?php include "inc/header.php"; $newfolder = $username; if (!mkdir($newfolder, 0777, true)) { die('Failed to create folders...'); } $pagename = $username; $newFileName = './u/'.$username.'/'.$pagename.".php"; $newFileContent = '<?php echo "something..."; ?>'; ?>
To make a directory/file制作目录/文件
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"
}
Now the possible error and some tips现在可能的错误和一些提示
1) Most of people do fopen("filename_with_PATH", "w") and expect that file will be generated in PATH folder ! 1)大多数人都做 fopen("filename_with_PATH", "w") 并期望该文件将在 PATH 文件夹中生成! Some times it might fall wrong (depends on version)
有时可能会出错(取决于版本)
fopen is meant to create a file in the directory where your php resides
fopen 是为了在你的 php 所在的目录中创建一个文件
2) check ur php permission in php.ini if u dont give php permission to write,remote access then u might get some errors (it will be displayed that u have error in my script) 2)在 php.ini 中检查你的 php 权限,如果你没有给 php 写权限,远程访问那么你可能会得到一些错误(它会显示你在我的脚本中有错误)
3)For more info and tinkering file_put_contents 3) 有关更多信息和修改file_put_contents
Hope this will be helpful for you ..希望这对你有帮助..
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.