eugene2009 Posted October 9, 2009 Share Posted October 9, 2009 So i have a generator where the user inputs the variable values and then it is automatically inserted in a code on the next page in a text box. How can I have the user then click on a button that says something like "Save" and will allow them to save that code in a .txt file? Please help Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/ Share on other sites More sharing options...
bmdsherman Posted October 9, 2009 Share Posted October 9, 2009 http://us3.php.net/manual/en/function.fopen.php Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/#findComment-933456 Share on other sites More sharing options...
eugene2009 Posted October 9, 2009 Author Share Posted October 9, 2009 Heres the code: <?php $filename = "myfile.txt"; //first, obtain the data initially present in the text file $ini_handle = fopen($filename, "r"); $ini_contents = fread($ini_handle, filesize($filename)); fclose($ini_handle); //done obtaining initially present data //write new data to the file, along with the old data $handle = fopen($filename, "w+"); $writestring = "text to write to file\n" . $ini_contents; if (fwrite($handle, $writestring) === false) { echo "Cannot write to text file. <br />"; } fclose($handle); ?> How exactly do I link that with the results? Sorry im new to php. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/#findComment-933472 Share on other sites More sharing options...
Jnerocorp Posted October 9, 2009 Share Posted October 9, 2009 something like this: $result1 = $_POST['']; $result2 = $_POST['']; $result3 = $_POST['']; $filename = $_POST['']; <?php $myFile = "$filename.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$result1 \r\n"; fwrite($fh, $stringData); $stringData = "$result2 \r\n"; fwrite($fh, $stringData); $stringData = "$result3 \r\n"; fwrite($fh, $stringData); fclose($fh); ?> you need to fill in some of the blanks but Ifthis is still not done 7 hours from now I will help you finish the whole script cuz i need to leave -John Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/#findComment-933658 Share on other sites More sharing options...
eugene2009 Posted October 9, 2009 Author Share Posted October 9, 2009 okay, do have have an IM? that way you will be able to assist me in a better way. thank you. Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/#findComment-933999 Share on other sites More sharing options...
Daniel0 Posted October 9, 2009 Share Posted October 9, 2009 okay, do have have an IM? that way you will be able to assist me in a better way. thank you. I think perhaps you've misunderstood what a forum is Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/#findComment-934010 Share on other sites More sharing options...
eugene2009 Posted October 10, 2009 Author Share Posted October 10, 2009 no i did not, im just asking if he'd be able to help me with it directly. Quote Link to comment https://forums.phpfreaks.com/topic/177039-saving-txt-file/#findComment-934063 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.