怎么解决PHP中的mkdir和fopen文件?

时间:2017-05-24 11:03:31

标签: php fopen fwrite mkdir fclose

当我想为注册到我的网站的会员做文件夹时此文件夹中是照片文件夹和会员的主文件。 这是问题: -

第一个文件夹已成功完成,但成员的照片文件夹和个人资料页面未成功。                                                                 谢谢 ..... 这是我的代码我改变了帮助我的人的代码  但同样存在问题 第一个文件夹已成功完成 问题在于 文件设置,文件夹,图像和索引

<?php
$us = "";
 if(isset($_POST['username'])){ $us= $_POST['username']; }

 if(isset($_POST['username'])){
        mkdir("../profiles/$us", 0777, true);
        mkdir("../profiles/$us/images", 0777, true);
        $filename = "../profiles/$us/index.php";
        $ourFileName = $filename;
        $ourFileHandle = fopen($ourFileName, 'w');

        $written = "
        <html>
        <body>
        <?php
        echo \"hi man \";
        </body>
        </html>
        ";
        fwrite($ourFileHandle, $written);
        fclose($ourFileHandle);
        $myfile = fopen("../profiles/$us/setting.php", "w") or die("Unable to open file!");
        fwrite($myfile, $txt);
        $txt = "Minnie Mouse\n";
        fwrite($myfile, $txt);
        fclose($myfile);

} ?&GT;

1 个答案:

答案 0 :(得分:0)

您无法在括号内指定$us = $_POST["username"],然后再次使用$us

括号内的任何内容都限制在这些括号内。

您必须在第一个语句的IF语句范围之外定义$us = ""

<?php
     $us = "";
     if(isset($_POST['username'])){ $us= $_POST['username']; }

     if(isset($_POST['username'])){

          etc etc
}