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
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...
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

It seems "useless" to me to check if the fwrite fails or not. If there no problem in fopen, there shoud be no problem with fwrite. So fopen(...) OR DIE("Whoops!"); is what I mostly use  :)
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.