newbie5050 Posted August 31, 2007 Share Posted August 31, 2007 hi guys, for a simple project i have to save some form data to a .txt file, using one of the form variables ( #studentid ) as the file name, e.g. if the #studentid submitted was 123 then the file would save as 123.txt. I have tried a number of different ways to do this but am stuck!!1 any help will be much appreciated!! Quote Link to comment https://forums.phpfreaks.com/topic/67382-writing-to-a-txt-file/ Share on other sites More sharing options...
Jessica Posted August 31, 2007 Share Posted August 31, 2007 Well, post your code and what the problem is. We're not going to write it for you. Quote Link to comment https://forums.phpfreaks.com/topic/67382-writing-to-a-txt-file/#findComment-338174 Share on other sites More sharing options...
pocobueno1388 Posted August 31, 2007 Share Posted August 31, 2007 Write to a text file: http://www.tizag.com/phpT/filewrite.php http://www.phphelps.com/9_How_to_write_a_file_in_PHP.shtml Create a text file: http://www.tizag.com/phpT/filecreate.php Quote Link to comment https://forums.phpfreaks.com/topic/67382-writing-to-a-txt-file/#findComment-338176 Share on other sites More sharing options...
Fadion Posted August 31, 2007 Share Posted August 31, 2007 A simple code: <?php $filename = $_POST['filename']; if(!file_exists($filename . ".txt")){ $handle = fopen($filename . ".txt", 'w+'); $content = 'some text here'; fwrite($handle, $content); fclose($handle); } else{ echo "The file u want to create already exists"; } ?> It will check if the file exists and if not it will create it with fopen and write some contents. Quote Link to comment https://forums.phpfreaks.com/topic/67382-writing-to-a-txt-file/#findComment-338179 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.