title: Using PHP to create and save XML in subfolder
body: <p>I'm using PHP to create and save xml files using this syntax:</p>
  
  <pre><code>$xml-&gt;save("source1.xml") or die("Error");
  </code></pre>
  
  <p>It worked fine until i realized that i have more than 300 sources. Meaning in my folder where the working files e.g.; my css and php files i would have additional 300++ xml files mixed together with my main working files. On top of that, instead of hardcoding "source1.xml" i made it dynamic based on the selected source and create the xml file dynamically if, say, the selected source is "source189.xml" and that particular file doesn't exist.</p>
  
  <p>So i added this before adding the nodes and child for xml doc:</p>
  
  <pre><code>$path = 'xml_'.$level.'_syll/';
  $filename = $src.'.xml';
  $file = $path.$filename;
  </code></pre>
  
  <p>With that, i save my xml using this:</p>
  
  <pre><code>$xml-&gt;save($file) or die("Error");
  </code></pre>
  
  <p>and got this error:</p>
  
  <pre><code>Warning: DOMDocument::save() [domdocument.save]: Unable to access xml_data_syll/source3.xml in file.php on line 85
  
  Warning: DOMDocument::save(xml_data_syll/source3.xml) [domdocument.save]: failed to open stream: No such file or directory in file.php on line 85
  Error
  </code></pre>
  
  <p>So i guessed it has something to do with permission. I googled and found a solution using chmod to grant the permission. so how do i insert the chmod during the file saving?</p>
  
  <p>I tried:
  $xml->save($file(chmod($file,0777))) or die("Error");</p>
  
  <p>and the error i got is:</p>
  
  <pre><code>Fatal error: Call to undefined function xml_data_syll/source3.xml() in file.php on line 86
  </code></pre>
  
  <p>Any pointers is much appreciated.</p>