Jump to content


Photo

Making a txt file from a HTML form


  • Please log in to reply
9 replies to this topic

#1 Elusid

Elusid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 27 July 2006 - 01:34 AM

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

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

<?php
$url = ???

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

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!

#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 27 July 2006 - 01:51 AM

I replied to your last post on this subject

http://www.phpfreaks....html#msg404313

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 27 July 2006 - 01:57 AM

also if you are wanting to do it this way then try is

$dir = "??";

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 Elusid

Elusid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 27 July 2006 - 02:04 AM

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

#5 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 27 July 2006 - 02:08 AM

you don't necessarly have to define the $dir. If you just used
$handle = fopen("url.txt", "x+")
it would create the text file in the same directory as this script.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#6 Elusid

Elusid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 27 July 2006 - 02:27 AM

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

#7 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 27 July 2006 - 02:36 AM

oh ok I didn't under stand what you meant.

try this

<?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);

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
fwrite

Hope this helps,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#8 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 27 July 2006 - 03:51 AM

I think that $_POST["url"] would help him on this one  ;)
I'm just a guy who likes to code for fun...

#9 Elusid

Elusid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 27 July 2006 - 05:26 AM

Yes thanks I got it through a friend. I used this

 $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!';} 


#10 Ifa

Ifa
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationRauma, Finland

Posted 27 July 2006 - 05:37 AM

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  :)
I'm just a guy who likes to code for fun...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users