legohead6 Posted July 10, 2006 Share Posted July 10, 2006 how to i make php create a new file with a specific name and content? Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/ Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 Look in the manual at the section on filesystems. http://www.php.net/manual/en/ref.filesystem.phpLook at the fopen(), fwrite(), and fclose() topics.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/#findComment-55671 Share on other sites More sharing options...
trq Posted July 10, 2006 Share Posted July 10, 2006 [url=http://php.net/fopen]fopen[/url]. Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/#findComment-55673 Share on other sites More sharing options...
legohead6 Posted July 10, 2006 Author Share Posted July 10, 2006 doesnt that just open a file? i need it to create the file! Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/#findComment-55674 Share on other sites More sharing options...
kenrbnsn Posted July 10, 2006 Share Posted July 10, 2006 Look at the manual page. There are options to the fopen() function which will let you create a file.Ken Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/#findComment-55675 Share on other sites More sharing options...
redarrow Posted July 10, 2006 Share Posted July 10, 2006 <?php$filename = 'test.txt';$somecontent = "Add this to the file\n";// Let's make sure the file exists and is writable first.if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle);} else { echo "The file $filename is not writable";}?> Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/#findComment-55679 Share on other sites More sharing options...
legohead6 Posted July 10, 2006 Author Share Posted July 10, 2006 o.. 'x+' ! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/14201-creating-a-new-file/#findComment-55681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.