Elusid Posted July 27, 2006 Share Posted July 27, 2006 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! Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 27, 2006 Share Posted July 27, 2006 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] Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 27, 2006 Share Posted July 27, 2006 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] Quote Link to comment Share on other sites More sharing options...
Elusid Posted July 27, 2006 Author Share Posted July 27, 2006 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 Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 27, 2006 Share Posted July 27, 2006 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. Quote Link to comment Share on other sites More sharing options...
Elusid Posted July 27, 2006 Author Share Posted July 27, 2006 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... Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 27, 2006 Share Posted July 27, 2006 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 $urland 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 Quote Link to comment Share on other sites More sharing options...
Ifa Posted July 27, 2006 Share Posted July 27, 2006 I think that $_POST["url"] would help him on this one ;) Quote Link to comment Share on other sites More sharing options...
Elusid Posted July 27, 2006 Author Share Posted July 27, 2006 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] Quote Link to comment Share on other sites More sharing options...
Ifa Posted July 27, 2006 Share Posted July 27, 2006 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 :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.