Jump to content

Archived

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

Elusid

Making a txt file from a HTML form

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!

Share this post


Link to post
Share on other sites
I replied to your last post on this subject

[url=http://www.phpfreaks.com/forums/index.php/topic,101870.msg404313.html#msg404313]http://www.phpfreaks.com/forums/index.php/topic,101870.msg404313.html#msg404313[/url]

Share this post


Link to post
Share on other sites
also if you are wanting to do it this way then try is

[code=php:0]
$dir = "??";

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

Share this post


Link to post
Share on other sites
Well how does it know where it is pulling the text from? That's all I am trying to get right I already have the $dir btw I just am lost on this one section of code

Share this post


Link to post
Share on other sites
you don't necessarly have to define the $dir. If you just used [code=php:0]$handle = fopen("url.txt", "x+")[/code] it would create the text file in the same directory as this script.

Share this post


Link to post
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...

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
I think that $_POST["url"] would help him on this one  ;)

Share this post


Link to post
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]

Share this post


Link to post
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  :)

Share this post


Link to post
Share on other sites

×

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.