glapo21 Posted September 11, 2010 Share Posted September 11, 2010 Hey, I am pretty new to php. I am creating a simple website to handle a http get I need to do for a Android Application. I can write to a file but I am unable to open it in a browser. It just shows a blank page. When I download it from my browser (Firefox) to my hard drive (Windows 7) using my ftp I can view the .txt file. All i want to do is write to a text file. Any help would be nice. Sorry for sparse information. I am hosting it on 000webhost.com. Thanks My Code: 3 files blank "data.txt", index.html, process.php Index.html <html><body> <h4>Tizag Art Supply Order Form</h4> <form action="process.php" method="post"> <select name="item"> <option>Paint</option> <option>Brushes</option> <option>Erasers</option> </select> Quantity: <input name="quantity" type="text" /> <input type="submit" /> </form> </body></html> process.php <html><body> <?php $quantity = $_POST['quantity']; $item = $_POST['item']; $myFile = "data.txt"; $fh = fopen($myFile, 'at') or die("can't open file"); $stringData = "Bobby Bopper"; fwrite($fh, $stringData); $stringData = "Tracy Tanner"; fwrite($fh, $stringData); fclose($fh); echo "You ordered ". $quantity . " " . $item . ".<br />"; echo "Thank you for ordering from Tizag Art Supplies!"; ?> </body></html> Quote Link to comment Share on other sites More sharing options...
WatsonN Posted September 12, 2010 Share Posted September 12, 2010 use this <?php $quantity = $_POST['quantity']; $item = $_POST['item']; $myFile = "data.txt"; $fh = fopen($myFile, 'a'); $stringData = "Bobby Bopper\n"; fwrite($fh, $stringData); $stringData = "Tracy Tanner\n"; fwrite($fh, $stringData); fclose($fh); echo "You ordered ". $quantity . " " . $item . ".<br />"; echo "Thank you for ordering from Tizag Art Supplies!"; ?> I dont see where the form is used at all except in the echo, maybe thats all you wanted. -edit- Made sure the php statement was closed. -edit- Quote Link to comment Share on other sites More sharing options...
glapo21 Posted September 12, 2010 Author Share Posted September 12, 2010 Hey, Thanks for the reply. Sorry all that code is just for testing. I will have a url HTTP GET specified in a Android Application. Here is my final code: getTask.php <html><body> <?php $time = $_GET['time']; $task = $_GET['task']; $myFile = "data.txt"; $fh = fopen($myFile, 'at') or die("can't open file"); $stringData = "Time Received: "; fwrite($fh, $stringData); fwrite($fh, $time); $stringData = " Task: "; fwrite($fh, $stringData); fwrite($fh, $task); $stringData = "\n\n"; fwrite($fh, $stringData); fclose($fh); ?> </body></html> Quote Link to comment Share on other sites More sharing options...
WatsonN Posted September 12, 2010 Share Posted September 12, 2010 Oh ok now I understand. At $fh = fopen($myFile, 'at') or die("can't open file"); I'm pretty sure you want: $fh = fopen($myFile, 'a+') or die("can't open file"); a+ not at there is no fopen mode "t" at-least that i've heard of. Quote Link to comment Share on other sites More sharing options...
glapo21 Posted September 12, 2010 Author Share Posted September 12, 2010 Well I heard somewhere t was a translation flag for windows/linux \n and \r\n I am not 100% sure either. I can write to the file "data.txt" fine. I can download it using my ftp. However I cannot access it anywhere else. I cant download it using a browser or a download manager. I have other files on this server that I can download. The permission for the .txt file is 666. Any idea? Quote Link to comment Share on other sites More sharing options...
WatsonN Posted September 12, 2010 Share Posted September 12, 2010 mine is 644 and i can load it in a browser just fine. Hmmm is the directory permissions or .htaccess preventing it? Quote Link to comment Share on other sites More sharing options...
glapo21 Posted September 12, 2010 Author Share Posted September 12, 2010 Well I have to set it to 666 or I cant write to the file. It seems that my hoster does not like .txt files. I cant access any .txt files. I can download other files though really weird. Any ideas? Quote Link to comment Share on other sites More sharing options...
WatsonN Posted September 12, 2010 Share Posted September 12, 2010 change the extension from "txt" to something like "php" "html" or make up your own extension Quote Link to comment Share on other sites More sharing options...
glapo21 Posted September 12, 2010 Author Share Posted September 12, 2010 Thanks Watson that did it! Quote Link to comment 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.