簡體   English   中英

PHP 用戶個人資料頁面

[英]PHP user profile page

我正在嘗試創建一個包含用戶的網站,並且我正在嘗試創建一個腳本,以便每當新用戶注冊時,它都會自動為他們創建一個用戶文件夾和配置文件,但是當我嘗試注冊時,它不會創建文件,
有人可以幫我解決這個問題嗎,謝謝

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

制作目錄/文件

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

希望這對你有幫助..

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM