title: Why file is not creating in CGI with Apache?
body: <p>I want to write some contents to a file using CGI with Apache . </p>
  
  <p><strong>my HTML file :</strong></p>
  
  <p>using Ajax HTTP method to call CGI script . I am not passing any arguments to the CGI . Finally i am printing response text to a div.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;script&gt;
  
  var xhttp;
  
  function loadDoc() {
  
      try{
  
            xhttp = new XMLHttpRequest();
  
            xhttp.onreadystatechange = function() {
  
                  if (this.readyState == 4 &amp;&amp; this.status == 200) {
                       document.getElementById("message").innerHTML = this.responseText;
                  }
            };
  
            xhttp.open("POST","mycgi.cgi",true);
            xhttp.send();
  
  
      }catch (exception){
  
              alert("Request failed: " + exception.message);
          }
  }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
  &lt;h2&gt;sample ajax&lt;/h2&gt;
  
  &lt;button type="button" onclick="loadDoc()"&gt;Change Content&lt;/button&gt;
  
  &lt;div id ="message" /&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>and <strong>cgi.cpp file</strong> </p>
  
  <p>Here i creating a file with write mode , write some contents to that file and successfully close . Send response text "successfully write " to HTML back .</p>
  
  <pre><code>    #include &lt;unistd.h&gt;
      #include &lt;iostream&gt;
      #include &lt;vector&gt;
      #include &lt;string&gt;
  
      #include "cgicc/Cgicc.h"
      #include "cgicc/HTTPHTMLHeader.h"
      #include "cgicc/HTMLClasses.h"
  
      #include &lt;stdio.h&gt;
      #include &lt;string.h&gt;
      #include &lt;fstream&gt;
  
      using namespace std;
      using namespace cgicc;
  
      int main(int argc, char **argv)
      {
  
      Cgicc cgi;    
  
         try {
  
          ofstream myfile;
          myfile.open ("Newcgi.txt",ios::out);
          cout&lt;&lt;"Content-Type: text/html\n\n";
          myfile &lt;&lt; "Writing this to a file.\n";
          cout&lt;&lt;"Sucessfully write";
          myfile.close();
  
         }
         catch(exception&amp; e) {
  
         }
  
       return 0;
  
      }
  </code></pre>
  
  <p>But i can not see any file created in <code>/var/apache2</code> or in <code>/var/www/html</code> . Why this is happening ? Where should be a new file created ? is it in Apache directory ?  </p>
  
  <p>Any code problem ? I am writing to a file with write mode also . I think code is working fine . Any suggestions ?  </p>