0

I want to know the code for file handling function write(). Its should add a text in file from user input and shoe it to the screen in new window.Kindly if any one know the code reply here its urgent. Thanks.

2
Contributors
4
Replies
15
Views
4 Years
Discussion Span
Last Post by ryantroop
1

in php, you would use echo.

<?php

$myVar = "A String";

echo ($myVar);

?>

there are others... it all sort of depends on what you are trying to do.

If you want users to input data and put it on the screen, there are many ways to do that... it all sort of depends on what you want as a finished product, but they all generally follow this scenario..

1) send data with get or post (using a form or ajax call).
2) process the data.
3) spit something out (even if it's the same data that was sent in, or nothing.)

For example...
a php file called "myphp.php"...

<?php

if (isset($_GET['text']))
{
    if ($_GET['text'] != "whatever")
    {
        echo ($_GET['text']);
    }
}

?>

You could use an HTML form to send your data...

<html>
<head><title>test</title></head>
<body>
<form method="GET" action="myphp.php" target="_blank">
<input type="text" name="text" />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Now, that whole "open in a new screen" thing..

since your form is targetting "_blank" it will open in a new window (unless you have an iframe called "_blank"... but then you have different issues).

I think that's what youre asking...

Hope that helps,

Ryan

0

Thanks bro for your coperation in my problem but actually I was asking about the file handling. Code for that is given below ....

0

I was asking that by using this code I want to show the text written in the text area on the screen on next page. I hope now you could understand what im sayiing and help me in this matter.

//php code
<?php

$file = $_POST['file_name'];
if($file == "")
{
  echo "please enter file name";
}
else{
$fh= fopen($file,"w") or die ("Cannot open file or It is not loacated in the directory");

if ($fh) 

$fh1= fwrite($fh,($_POST["text"]));
echo $fh1;
fclose($fh);

}

?>
//html code.........!
<form name="fecth" id="" method="post" action="proc2.php" enctype="multipart/form-data">
File name:<input type="text" name="file_name"  id="" value="" /><br /><br />
enter text:<textarea cols="20" rows="3"  name="text"></textarea><br /><br />
submit:<input type="submit" name="submit" id="" value="submit" />
</form>
0

Im not sure I follow what you are trying to do... are you trying to add to a file?

If you are adding to a file, you have to fwrite first, then fread to get the data back out.

In your example, I think that you are going to echo a boolean (true/false) as to whether or not the fwrite performed successfully...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.