create file php code example
Example 1: write to file php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, "Content to write to file");
fclose($myfile);
Example 2: php create temporary file
$dir = sys_get_temp_dir();
$tmp = tempnam($dir, "foo");
file_put_contents($tmp, "hello");
Example 3: write in a file using php
<?php
$myfile = fopen("file_name.txt", "w") or die("Unable to open file!");
$txt = "Hello world\n";
fwrite($myfile, $txt);
$txt = " Php.\n";
fwrite($myfile, $txt);
fclose($myfile);
?>