Q: PHP script not creating and writing a JSON file I have a PHP script which get it's post data from my C# code. My C# code sends POST data to my PHP script including a base64 string and a filename. With these two pieces of data it should create a JSON file in the folder JSON with the filename and then it should write the decoded base64 string to the file it just created. After this it should save the JSON data to a database. But there's one problem, It doesn't create the JSON file and it saves blank data to my database. Here is what I have so far:
PHP:
<?php
$link = new mysqli($host, $user, $pass, $db);
if($link ->connect_errno) 
{
    echo 'Database connection wrong<br/>';
}
else 
{
    if(isset($_POST['filename']) && isset($_POST['b64string']))
    {
        $jsonstring = base64_decode($_POST['b64string']);
        $filename = $_POST['filename'] . '.json';

        $create = fopen(__DIR__. "/json/" . $filename, "W+");
        fwrite($create, $jsonstring);

        $json = fread($create, filesize(__DIR__. "/json/" . $filename));
        fclose($create);

        $obj = json_decode($json);

        $query_opslaan = "INSERT INTO SalesKicker (BedrijfsNaam, ContPers, TelNr, Email, Land, Plaats, POC) VALUES ('". $obj->bedrijfsNaam ."' , '". $obj->ContPers ."', '". $obj->TelNum ."', '". $obj->email ."', '". $obj->Land ."', '". $obj->Plaats ."', '". $obj->PostCode ."')";



        mysqli_query($link, $query_opslaan) or die(mysqli_error($query_opslaan));
    }
    else
    {
        echo 'ERROR: no data!';
    }

}
?>

It get's the data from the following C# script:
        if (reqCat == "bvg")
        {
            json = "{\"bedrijfsNaam\":\"" + bedrijfsNaam + "\"," +
                            "\"ContPers\":\"" + ContPers + "\"," +
                            "\"TelNum\":\"" + TelNum + "\"," +
                            "\"email\":\"" + email + "\"," +
                            "\"Land\":\"" + Land + "\"," +
                            "\"Plaats\":\"" + Plaats + "\"," +
                            "\"PostCode\":\"" + PostCode + "\"}";

            var b64bytes = System.Text.Encoding.UTF8.GetBytes(json);
            b64encode = System.Convert.ToBase64String(b64bytes);

            using (WebClient client = new WebClient())
            {
                byte[] sendB64 = client.UploadData("http://" + ConfigurationManager.AppSettings["scripturi"].ToString() + "SalesKicker.php", "POST",
                System.Text.Encoding.ASCII.GetBytes("b64string=" + b64encode + "&filename=" + dt.bedrijfsNaam));
            }
        }

This is my folder structure:

public_html (this is where all the PHP stuff is located) -> json (the folder where it should be saved)

I don't really know what to do at the moment so I came here to post my problem. Can someone please help me out and tell me what I'm doing wrong here?

A: Got it!
You sending 'filename' param in the POST body, but checking it in the GET array. So you don't even go into the your if(){} statement.
You need either change
if(isset($_GET['filename']) && isset($_POST['b64string']))

to
if(isset($_POST['filename']) && isset($_POST['b64string']))

either change in C#
            byte[] sendB64 = client.UploadData("http://" + ConfigurationManager.AppSettings["scripturi"].ToString() + "SalesKicker.php", "POST",
            System.Text.Encoding.ASCII.GetBytes("b64string=" + b64encode + "&filename=" + dt.bedrijfsNaam));

to
            byte[] sendB64 = client.UploadData("http://" + ConfigurationManager.AppSettings["scripturi"].ToString() + "SalesKicker.php?filename=" + dt.bedrijfsNaam, "POST",
            System.Text.Encoding.ASCII.GetBytes("b64string=" + b64encode));


A: I wasn't sure at first but after testing here the solution:
wrong:
$create = fopen(__DIR__. "/json/" . $filename, "W+");

correct:
$create = fopen(__DIR__. "/json/" . $filename, "w+");

It's kind of stupid but capital letters in the mode are not valid. Hope this solves the issue :)

A: That moment when a C# programmer forgets about the caches. I was a bit clumsy but after searching for the method how to clear a cache in PHP I found it. Behold, the legendary clearstatcache() method. My final working PHP code looks like this:
    if(isset($_POST['filename']) && isset($_POST['b64string']))
    {
        clearstatcache();//the solution to my problem

        $jsonstring = base64_decode($_POST['b64string']);

        $filename = $_POST['filename'] . '.json';

        $create = fopen(__DIR__. "/json/" . $filename, "w+");
        fwrite($create, $jsonstring);

        $json = fread($create, filesize(__DIR__. "/json/" . $filename));
        fclose($create);

        $obj = json_decode($json);

        $query_opslaan = "INSERT INTO SalesKicker (BedrijfsNaam, ContPers, TelNr, Email, Land, Plaats, POC) VALUES ('". $obj->bedrijfsNaam ."' , '". $obj->ContPers ."', '". $obj->TelNum ."', '". $obj->email ."', '". $obj->Land ."', '". $obj->Plaats ."', '". $obj->PostCode ."')";



        mysqli_query($link, $query_opslaan) or die(mysqli_error($query_opslaan));
    }

