File did not save to specific folder(directory creation)
<p>I try to save my file status.txt to a specific directory call social. I created the directory social but for some reason my status.txt name its name is socialstatus.txt and the status.txt file is place not inside the social directory but at the same folder where the social directory is (I hope I don't confuse you.)</p>

<p>I try to do this but it seems something to do with the placement of the code...
those coding to save file to directory is the one that start if(!file_exists($newdir)){</p>

<p>Thank you so much for the big help</p>

<pre><code>&lt;?php

$newdir = "../../data/social";
umask(0007);



$errors = array();
$permissionsArray = (isset($_POST['permission']) ? $_POST['permission'] : null);


if (isset($_POST["statuscode"])) 
{
    $statusCode = $_POST["statuscode"];
    $patternCode = "/^S[0-9]{4}$/";
    if (preg_match($patternCode, $statusCode)) 
    {
        $ans = "";
        $length = strlen($statusCode);
        echo $statusCode . "&lt;br /&gt;";
    }
}
else
{
    array_push($errors, "Please fill in Status Code as they are mandatory field");
}

if (isset ($_POST["status"])) 
{
    $status = $_POST["status"];
    $pattern = "/^[a-zA-Z0-9\s\.,!?]*$/";
    if (preg_match($pattern, $status)) 
    {
        echo $status . "&lt;br /&gt;";
    }
}
else
{
    array_push($errors, "&lt;b&gt;Error:&lt;/b&gt; Please fill in Status as they are mandatory field!");
}

if (isset ($_POST["share"])) 
{
    $shareButton = $_POST["share"];
    echo $shareButton . "&lt;br /&gt;";
}
else
{
    //Not possible unless in exceptional circumstances
    array_push($errors, "Please choose a share");
}

if (isset($_POST["date"])) 
{
    $date = date("d/m/y");
    echo $date . "&lt;br /&gt;";
} else {
    $date = $_POST["date"];
} 

if (isset($permissionsArray)) 
{
    foreach($permissionsArray as $permission){
        echo $permission . "&lt;br /&gt;";
    }
}

if(!file_exists($newdir)){
    mkdir($newdir, 02770);

$statusTxt = fopen($newdir. "status.txt", "a");

if  (is_writeable($newdir. "status.txt")) {
    if (fwrite($statusTxt, $statusCode . " " . $status . " " . $shareButton . " " . $date . " " . $permission . "\n"))
{
}
    echo "&lt;p&gt;Your form has succesfully been submit!&lt;/p&gt;";
}
fclose($statusTxt);
}


if(isset($statusCode, $status))
{
    //if(empty($statusCode) || empty($status))
    //{
    //array_push($errors, "Please fill in the required part!");
    //}
    if (0 === strlen($statusCode &gt; 5 || $statusCode &lt; 5)) 
    {
        array_push($errors, "&lt;b&gt;Error:&lt;/b&gt; You characters length is either less or more than 5 characters&lt;br/&gt;");
    }
    if (0 === preg_match("/\S+/", $statusCode)) 
    {
        array_push($errors, "&lt;b&gt;Error:&lt;/b&gt; You forgot to fill in Status Code!&lt;br/&gt;");
    }
    if (0 === preg_match("/\S+/", $status)) 
    {
        array_push($errors, "&lt;b&gt;Error:&lt;/b&gt; You forgot to fill in the Status! &lt;br/&gt;");
    }
    if (0 === preg_match($patternCode, $statusCode)) 
    {
        array_push($errors, "&lt;b&gt;Error:&lt;/b&gt; please make sure that the first letter in Status Code is uppercase 'S' following by 4 numbers. &lt;br/&gt;");
    }
    if (0 === preg_match($pattern, $status)) 
    {
        array_push($errors, "&lt;b&gt;Error:&lt;/b&gt; Please make sure to avoid symbols other than \",.?!\" &lt;br/&gt;");
    }
}


if (isset($errors)) 
{
    foreach ($errors as $error) 
    {
        echo '&lt;strong&gt;', $error, '&lt;/strong&gt;';
    }
}

echo '&lt;a href="phpstatusform.php"&gt;Back to Form page.&lt;/a&gt; &lt;br /&gt;';

echo '&lt;a href="index.php"&gt;Back to Home page.&lt;/a&gt;'; 


?&gt;
</code></pre>
