Issue
I have this code
$ext = ".txt";
$filename = $namef.$ext;
if(!file_exists($filename))
{
$file = fopen($filename,"w");
fwrite($file, $privatekey);
fclose($file);
chmod($file,0777);
}
$namef
is any name that gets input into this program.
However when I run this, I keep getting:
Unable to access (name_of_file).txt in something.php
Warning: fopen(name_of_file.txt) [function.fopen]: failed to open stream: No such file or directory in something.php
Warning: fwrite(): supplied argument is not a valid stream resource in ./something.php on line 79
Warning: fclose(): supplied argument is not a valid stream resource in ./something.php on line 80
Warning: chmod() [function.chmod]: Unable to access in ./something.php on line 81
May i know if dynamic text file name creation is possible?
Thank you
Solution
Write this simple code no need of if statements. it will open the file in read write mode and create automatically if it doesn,t exist or open a file if it already exists.
$ext = ".txt";
$filename = $namef.$ext;
$file = fopen($filename,"w+");
fwrite($file, $privatekey);
fclose($file);
chmod($file,0777);
Answered By - Yasir Ahmed Answer Checked By - Senaida (WPSolving Volunteer)