Results 1 to 3 of 3

Thread: creating a folder

  1. #1
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default creating a folder

    I am trying to make something like a cms.
    but what I am doing is using fopen, stuff like that,

    what I am trying to do is create a folder with the username and put index.html inside it, but I can't seem to figure this out.

    this is what i am using.
    Code:
    <?
    include("session.php");
    ?>
    
    <?php
    /**
     * Logged in
     */
    if($session->logged_in){
    ?>
    
    <?php
    $loadcontent = "$session->username/index.html"; 
        if($save_file) { 
            $savecontent = stripslashes($savecontent); 
            $fp = @fopen($loadcontent, "w"); 
            if ($fp) { 
                fwrite($fp, $savecontent); 
                fclose($fp);
    print '<a href='.$_SERVER[PHP_SELF].'>Refresh</a>'; 
    print "<html><head><META http-equiv=\"refresh\" 
    
    content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>"; 
     
    } 
    } 
        $fp = @fopen($loadcontent, "r"); 
            $loadcontent = fread($fp, filesize($loadcontent)); 
    $lines = explode("\n", $loadcontent);
    $count = count($lines);
            $loadcontent = htmlspecialchars($loadcontent); 
            fclose($fp); 
    for ($a = 1; $a < $count+1; $a++) {
    $line .= "$a\n";
    }
    ?> 
    <form method=post action="<?=$_SERVER[PHP_SELF]?>"> 
    <input type="submit" name="save_file" value="Save">    
    <BR>
    <table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; 
    
    overflow: auto; border: 0px groove; font-size: 12px" name="lines" cols="4" 
    
    rows="<?=$count+3;?>"><?=$line;?></pre></td>
        <td width="97%" align="left" valign="top">
    
    <textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; 
    
    font-size: 12px" name="savecontent" cols="150" rows="<?=$count;?>" 
    
    wrap="OFF"><?=$loadcontent?></textarea></td>
      </tr>
    </table>
     
    <br> 
    <input type="submit" name="save_file" value="Save">    
    </form>
     
    <?php 
    
    }else{
    
    echo "Login please!";
    
    }
    
    ?>
    I thought i could do something like this and create a folder with the file in it but I was wrong
    $loadcontent = "$session->username/index.html";

    please help! thanks
    Hey new design new look, goto xudas for personal webdsign help.. (:

  2. #2
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    double post sorry...

    I want to know if this is safe.. oh I got it to work, could you tell me if it is safe to use though..

    Code:
    <?
    include("session.php");
    ?>
    
    <?php
    /**
     * Logged in
     */
    if($session->logged_in){
    ?>
    
    <?php
    mkdir("$session->username");
    
    
    $loadcontent = "$session->username/index.html"; 
        if($save_file) { 
            $savecontent = stripslashes($savecontent); 
            $fp = @fopen($loadcontent, "w"); 
            if ($fp) { 
                fwrite($fp, $savecontent); 
                fclose($fp);
    print '<a href='.$_SERVER[PHP_SELF].'>Refresh</a>'; 
    print "<html><head><META http-equiv=\"refresh\" 
    
    content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>"; 
     
    } 
    } 
        $fp = @fopen($loadcontent, "r"); 
            $loadcontent = fread($fp, filesize($loadcontent)); 
    $lines = explode("\n", $loadcontent);
    $count = count($lines);
            $loadcontent = htmlspecialchars($loadcontent); 
            fclose($fp); 
    for ($a = 1; $a < $count+1; $a++) {
    $line .= "$a\n";
    }
    ?> 
    <form method=post action="<?=$_SERVER[PHP_SELF]?>"> 
    <input type="submit" name="save_file" value="Save">    
    <BR>
    <table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
      <tr>
        <td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; 
    
    overflow: auto; border: 0px groove; font-size: 12px" name="lines" cols="4" 
    
    rows="<?=$count+3;?>"><?=$line;?></pre></td>
        <td width="97%" align="left" valign="top">
    
    <textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; 
    
    font-size: 12px" name="savecontent" cols="100" rows="<?=$count;?>" 
    
    wrap="OFF"><?=$loadcontent?></textarea></td>
      </tr>
    </table>
     
    <br> 
    <input type="submit" name="save_file" value="Save">    
    </form>
     
    <?php 
    
    }else{
    
    echo "Login please!";
    
    }
    
    ?>
    Hey new design new look, goto xudas for personal webdsign help.. (:

  3. #3
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Well, you wouldn't want just any username allowed.
    I like to use "~username", or "_username", since that won't conflict with anything else.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •