PHP用户个人资料页面

时间:2016-10-08 00:01:16

标签: javascript php html

我正在尝试创建一个包含用户的网站,我正在尝试创建一个脚本,这样每当新用户注册它时,它会自动为它们创建一个用户文件夹和配置文件,但是当我尝试注册时它不会创建文件,有人可以帮助我,谢谢

<?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..."; ?>';
?>

1 个答案:

答案 0 :(得分:1)

制作目录/文件

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”) 并期望该文件将在PATH文件夹中生成! 有时可能会出错(取决于版本)

  

fopen用于在php所在的目录中创建一个文件

2)检查php.ini中的php权限如果你不给php写入权限,远程访问则可能会出现一些错误(会显示你的脚本中有错误)

3)了解更多信息并修补file_put_contents

希望这会对你有所帮助..