Jnerocorp Posted October 11, 2009 Share Posted October 11, 2009 Hello, For some reason this code is not working for me it is creating that file and I can save it but there is nothing in the .txt file here is my code: <html> <head> <title>Form & Form Output</title> </head> <body> <center> <h1> Generate </h1><br> <?php if(isset($_POST['submit'])) { $imgurl = $_POST['imgurl']; $filename = rand(); $fullurl = "<img src='$imgurl'>"; $myFile = "$filename.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "$fullurl"; fwrite($fh, $stringData); fclose($fh); echo $fullurl ?> <br><br> <textarea cols="50" rows="10"><img src="<?php echo $imgurl ?>"></textarea><br> Right Click <a href='./<?php echo "$filename.txt"; ?>'>Here</a> and Click "Save as". <?php } else { ?> <form action="<?php $_SERVER['PHP_SELF']; ?>" method=POST> <p>This will generate an image code to put on your website.</p> <table> <tr> <td>Direct link:</td><td><input type=text name="imgurl" size="100"></td> <tr> <td><input type=submit name="submit" value="GET CODE!"></p></td> </tr> </table> </form> <?php } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/ Share on other sites More sharing options...
mikesta707 Posted October 11, 2009 Share Posted October 11, 2009 hmm, I don' see anything particularly wrong with this code. are you sure your filename is right, and that you are opening the right file name? try to echo out the variable. remember, since you have the open mode to 'w', it will overwrite anything that was previously there before. you can append information with 'a' Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934725 Share on other sites More sharing options...
Jnerocorp Posted October 11, 2009 Author Share Posted October 11, 2009 I do have it echoed its part of the script and it works the text file is created its just a randomly generated name using "$filename = rand();" I really am confused on what the problem is -John Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934728 Share on other sites More sharing options...
Jnerocorp Posted October 11, 2009 Author Share Posted October 11, 2009 I tried adding error_reporting(-1); but theres still no errors -John Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934731 Share on other sites More sharing options...
Jnerocorp Posted October 11, 2009 Author Share Posted October 11, 2009 now i tried adding : <?php error_reporting(E_ERROR | E_WARNING | E_PARSE); error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); error_reporting(E_ALL ^ E_NOTICE); error_reporting(E_ALL); ?> and still nothing :'( Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934732 Share on other sites More sharing options...
PFMaBiSmAd Posted October 11, 2009 Share Posted October 11, 2009 You need the following two lines to both report and display all php errors - ini_set("display_errors", "1"); error_reporting(E_ALL); Your code worked as expected for me. Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934734 Share on other sites More sharing options...
Jnerocorp Posted October 11, 2009 Author Share Posted October 11, 2009 its prob my free hosting it sucks so bad -John Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934737 Share on other sites More sharing options...
mikesta707 Posted October 11, 2009 Share Posted October 11, 2009 try $myFile = $filename.".txt"; i dont see how much of a difference that will make tho Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934738 Share on other sites More sharing options...
TheJoey Posted October 11, 2009 Share Posted October 11, 2009 try testing it on localhost first using xampp or something. Quote Link to comment https://forums.phpfreaks.com/topic/177282-helping-adding-text-to-txt-file/#findComment-934750 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.