在目录中创建文件

I am trying to create a file in a sub directory but it is not creating it

$tempFilename = "xml/tempfile.xml";
    if(file_exists($tempFilename))
            {    
                unlink($tempFilename);
            }
        $file = fopen($tempFilename,"w");
        $fileTemplate = ($xml);

Use fwrite :

$tempFilename = "xml/tempfile.xml";
// Test if directory exists.
$dirname = dirname($tempFilename);
if (!is_dir($dirname))
{
    mkdir($dirname);
}
if(file_exists($tempFilename)){    
     unlink($tempFilename);
}
$file = fopen($tempFilename,"w");

// Write what you need
fwrite($file, 'content of my file');
fclose($file);

You can use file_put_contents

file_put_contents($tempFilename, '23');

try this

first you need to create directory

$path = '/xml';
mkdir($path, 0777, true);
$tempFilename = "/xml/tempfile.xml";
if(file_exists($tempFilename))
        {    
            unlink($tempFilename);
        }
    $file = fopen($tempFilename,"w");
   fwrite($file, '23');
fclose($fp);