Jump to content

Making a txt file from a HTML form


Elusid

Recommended Posts

Ok so I have a quick question here. I made an HTML form with this code
[code]
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="affiliateupload.php">
Your URL<br>
<input type='text' name='url'>
</form>
[/code]

and I have this code so far to write the actual txt file in php

[code]
<?php
$url = ???

$url = '$dir/url.txt';
$handle = fopen($url);
fwrite($handle, $text);
fclose($handle);
?>
[/code]

ok what would I set the $url variable to if I want it to take the text from the form "url" and write it into a text file? I am getting better at php but by no means good enough to do everyting quite on my own yet. Any help would be appriciated thanks!
Link to comment
https://forums.phpfreaks.com/topic/15763-making-a-txt-file-from-a-html-form/
Share on other sites

but I want it where I have the $dir thats the point. That's not what I am having a prob with. Ok here... lets say that in the form that is a textbox named url you put in http://google.com and hit submit. I want the php to make a text file in $dir that when opened has http://google.com in it...
oh ok I didn't under stand what you meant.

try this

[code=php:0]<?php
$posted = "This person posted a new message(or what ever)
There url is $url
and there message is:
$text";

$page = '$dir/url.txt';
$handle = fopen($page "x+");
fwrite($handle, $posted);
fclose($handle);[/code]

All you have to do is put the variables from your form into something like $posted or what ever and then put that into the [code=php:0]fwrite[/code]

Hope this helps,
Tom
Yes thanks I got it through a friend. I used this

[code]
$url = $_POST['url'];
$comments = $_POST['comments'];
$urlfile = fopen($dir . 'url.txt','a+');
$commentsfile = fopen($dir . 'comments.txt','a+');
  if ( ( fwrite($urlfile,$url) ) && ( fwrite($commentsfile,$comments) ) )
{ echo 'Success!';} else { echo 'Failure!';}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.