Jump to content

Cant view fwrite text file in Browser


glapo21

Recommended Posts

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>

Link to comment
Share on other sites

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-

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.