PHP - Saving Content From Textarea Into A File
I am trying to create a program to get input from user in textarea and save that input into a text file.
But this code is only creating an empty file.
<?php echo <<<_END <form action="form.php" method="post"> <textarea name="textdata" cols="50" rows="20"></textarea> <input type="submit" name="submit" value="CLICK ME"> <input type="hidden" name="submit_check" value="1"> </form> _END; function write(){ $fname="test.txt"; $fh=fopen($fname,'w'); $data=$_POST['textdata']; fwrite($fname,$data); fclose($fh); } if(isset($_POST['submit_check'])){ write(); } ?>please help me. sorry for bad english Edited by mac_gyver, 24 August 2014 - 12:11 PM. code tags please Similar TutorialsCode: [Select] <html> <title>MyBB PM Exporter</title> <body> <form action ="<?php $_SERVER['PHP_SELF'] ?>" method="post"> URL to site: <input type ="text" name="site" value='community.mybb.com' /><br> Full path to user:pwd list: <input type ="text" name="path" value='/home/www/list.txt' /><br> <input type = "submit" value="Export" /> </form> </body> </html> <?php if(isset($_POST['path']) && isset($_POST['site'])) { $list = $_POST['path']; $url = $_POST['site']; $file = file($list); foreach($file as $line){ $explode = explode(":",$line); $username = $explode[0]; $password = $explode[1]; $crl = curl_init(); curl_setopt($crl, CURLOPT_URL, $url."/member.php"); curl_setopt($crl, CURLOPT_COOKIEFILE, "/tmp/cookie.txt"); curl_setopt($crl, CURLOPT_COOKIEJAR, "/tmp/cookie.txt"); curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($crl, CURLOPT_POST, 1); // This array will hold the field names and values. $postdata=array( "username"=>"$username", "password"=>"$password", "remember"=>"no", "submit"=>"Login", "action"=>"do_login", "url"=>$url."/member.php" ); // Tell curl we're going to send $postdata as the POST data curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata); $result=curl_exec($crl); $find_key = preg_match('/var my_post_key = "(.*?)"/',$result,$match); $my_post_key = $match[1]; curl_setopt($crl, CURLOPT_URL, $url."/private.php"); curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($crl, CURLOPT_POST, 1); // This array will hold the field names and values. $postdata=array( "my_post_key" => $my_post_key, "exportfolders[]" => "all", "dayway" => "disregard", "exportunread" => "1", "deletepms" => "0", "exporttype" => "html", "action" => "do_export", "submit" => "Export Private Messages" ); curl_setopt ($crl, CURLOPT_POSTFIELDS, $postdata); $fh = fopen($username.".html", 'w'); curl_setopt($crl, CURLOPT_FILE, $fh); curl_exec($crl); fclose($fh); curl_close($crl); } } ?> So , basically this code just opens the file where username:password is located and then it logins to community.mybb.com with each combination in that file and saves the content of pm's of logged in user. Problem is that this script allways saves pm's of only one user and it saves other usernames pm's but with the same content of the first user. Hi guys, Sorry if this is too dumb, I'm a student yet .. I have: $newEmail = preg_replace($patterns, $replacements, $email); How can I save $newEmail contents into an html file? Thanks a lot!! Hello
Is it possible to save data from saved htm table from other website in our mysql database system
as I have problem that there is one htm page where i can get data but i want to save it in mysql table. as data is large on htm page
it was hard to copy so i want access it direct from php and save it in mysql table
please guide
awaiting your valuable reply.
Thank in advance
Hi guys, I searched the web for solutions, but no luck for my case so far. I have a custom CMS that uses tinymce and input text boxes in a form. The tinymce textarea as well as the input text boxes pull the current data from the database, and allows the user to change it, from where the changes are passed on to be updated in the database. All input text boxes work 100%, except for the tinymce textarea. It keeps on passing the original data that was pulled from the database, and not the changed data. The form (simplified): Code: [Select] <form enctype="multipart/form-data" method="post" action="page_update.php"> Button Name: <input type="text" name="btn_name" style="width:150px" value="<?php echo $current_link;?>"><br> Content: <textarea id="elm1" name="elm1" rows="15" cols="80" style="width: 80%"> <?php echo $current_content; ?> </textarea> <input type="hidden" name="pid" value="<?php echo $page_id; ?>"> <input type="submit" name="save" value="Submit" /> <input type="reset" name="reset" value="Reset" /> </form> The php code (simplified): Code: [Select] $upd_name = $_POST["btn_name"]; $upd_content = $_POST["elm1"]; $upd_pid = $_POST["pid"]; echo "Content = ".$upd_content; mysql_query("UPDATE pages SET Content='$upd_content', Link='$upd_name' WHERE ID=".$upd_pid); With the "echo" line I can see that the changed data wasn't passed, but the original data from the database. All my input text boxes works just fine. I have checked my code that the data isn't pulled from the database again somewhere between the form and the update code, and that is ruled out. For what it is worth, I have previously done something similar, except for that the form (with tinymce textarea) displayed in a javascript popup window, and the changed data was sent correctly. Any ideas? Thanks in advance From what I have so far is that I am reading a text file into a textbox. Now I want to update/append new information to my file(the information may contain HTML/PHP code, text etc.) after I click the save button so the contents can be read on a separate page called "edit.php". Any suggestions? (My first time using PHP on a higher level) The following is written in my editcontent1.php(I'm seperating each content block on my edit.php page into several editcontent(n).php files where n is = 1 to infinity) Here is before the html tags: <?php if ( isset ($_POST ['content']) ) { file_put_contents ('content1.txt', $_POST ['content'] ); } ?> Here is before the html tags: Code: [Select] <form action = "edit.php" method="post"> <textarea name="content" cols="" rows="" wrap="virtual" class="textarea1"> <?php include 'content1.txt'; ?> </textarea> <br /> <input type="submit" value="Save"> </form> Can't figure out why the page wont save after clicking save. $KOHDE="index.php?s=admin"; $LOMAKE_W = 400; $TEXTAREA_W = 50; $TEXTAREA_H = 20; $LOMAKE = mysql_real_escape_string($_GET["l"]); $LOMAKE2 = mysql_real_escape_string($_POST["lomake"]); after a few more lines... elseif ($LOMAKE2 == "etusivu"){ #Etusivun muokkaus $teksti = stripslashes($_POST["teksti"]); $f = fopen("etusivu.php", "w"); fwrite($f, $teksti); fclose($f); } elseif ($LOMAKE == "etusivu"){ #Etusivun muokkaus echo "<h1>Edit home page</h1>"; $f = file("etusivu.php"); echo "<form action='$KOHDE' method='post'> <textarea name='teksti' cols='$TEXTAREA_W' rows='$TEXTAREA_H'>"; for ($i = 0; $i < count($f); $i++){ $f[$i] = str_replace("\"", "''", $f[$i]); echo $f[$i]; } echo "</textarea> <input type='hidden' value='etusivu' name='lomake'/> <br><input type='submit' value='Save'/> </form><br/>"; html_ohje(); } I can't see where it has gone wrong. Can anyone help? Hey folks, I thought this would be simple but obviously not. I can get the data to display in the textarea from the text file. That's not an issue. The issue is, updating the text from the textarea and saving it in the file, while keeping the text in the textarea. Basically, I want to create a personal notepad inside the site I am making. Here is the code I am using: <form action="?admintext.txt" method=post> <textarea name="file_content" class="textarea1"><? include "admintext.txt"; ?></textarea><br/> <input type=submit name=submit value=Update> </form> Can anyone help with this? I tried loads of tips I found from Google but none worked. Hia, I'm having a form, containing an image upload, a textarea and some other fields. I have a fileupload, where I check if the upload thingy is empty, with Code: [Select] if(empty($_POST['image'])) { echo "Error"; } else { //Do the imageUpload here } using the empty, isn't working for some reason, it proceed to the else anyway. Also, I have a textarea with name="productDesc", when I do: Code: [Select] <?php var_dump($_POST); ?> It doesn't return the textarea, and I can't see why it doesn't. Also the textarea proceed to the 'else' in the if else in the following code: http://codepad.org/wMd6SnoK Having a lot of questions these days Thank you guys! I have a textarea and a button, I would like by click a button, the text within the textarea will save as a .txt file and downloadable by user, how to do it with php?? Thanks!! This is the Code i am using. This is show error: Fatal error: Call to a member function item() on a non-object in /home/domain/public_html/forum/file/Test.php on line 35 Code: [Select] <?php $xml=("http://www.vn-zoom.com/external.php?type=RSS2&forumids=77"); $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); //get elements from "<channel>" $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; //output elements from "<channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>"); //get and output "<item>" elements $x=$xmlDoc->getElementsByTagName('item'); $i=1; // $i = 1 to n (I use For here). { $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; // If i remove this, it will work....//////////// $item_content=$x->item($i)->getElementsByTagName('content') ->item(0)->childNodes->item(0)->nodeValue; ///////////////////////////////////////////////////// echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); echo ("<br />"); echo ($item_content . "</p>"); } ?> Please help me Fix this Code to Get content of Tag Name <content:encoded> Thanks Hi, I'm a beginner, i had a problem about get content from file, i had searched but i can't solve my problem: I have a text file (abc.txt). It have content like this: _*Chapter*_ : ... Author: aaa ( and then content .......vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvv.......) _*Chapter*_ : ... Author: bbb ( and then content .........vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvvvvvvvvvvvvvvvvv.........) ..... and it loops like that. I have a string (abcxyz) that need to find in contents. If found it in content, print the name of the author (print all author have that content). the _*Chapter*_ is unique, in content hasn't got that word, but the word Author maybe. But beetween the Chapter and the Author, hasn't another word Author. Thanks a lot. PS: I need someone can help me to code this. (don't send me a link to example or something etc...) Hi! I'm a total stupid newbie. Please humor me. So, I'm trying to make a guestbook, just as practice. So far I have a form that writes entries to a file, each entry on a new line. Entries look like this: Code: [Select] 11:11 am, Oct 12th, 2010|name|website|message My dividing character between parts of the entries is the vertical bar. I don't know if that's a bad idea. As I said, I'm a newb. I should probably find out how to make a code that makes it so people can't use that character in the form. Anyway, this is my code so far trying to display the entries. So far, I just want to show the date of the first entry. $file = fopen("posts.txt", 'rb'); while(!feof($file) && fgetc($file) != "|"){ $date = $date.fgetc($file); } echo $date; fclose($file); I already have a problem. The code does stop at the vertical bar, but instead of showing the date as "11:11 am, Oct 12th, 2010" it shows "11 m c 2h 00". I'm just super confused, and I don't know what to do. Thanks. (: Hi, I am trying to fetch a file with function file_get_contents() from a website, but am getting following error. [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /data/22/1/27/17/1842180/user/1999295/htdocs/web/modules/index.php on line 14. using following code, Code: [Select] $content = file_get_contents($source); $handle = fopen($destination, 'wb'); fwrite($handle, $content); fclose($handle); does it have something to with http header, which might be required to set as HTTP/1.1 in php Regards, Abhishek im working on my website and im trying to insert text from a file into the webpage. the webpage is index.php the .txt file is indexbody.txt at the point of where the code is i would like to insert the contents of the text file into the html document so the person viewing the site can read it as if it was directly in that webpage. i hope you understand what im asking the current not working code is: <?php $myFile = "indexbody.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData;?> Hello, In m script, I need to get the content of another php file as a string, including the content of all the files which are included in it and in lower levels. Any idea how to do it? I tried output buffer+include but it doesn't get the content of the included files. Thanks I have a form that generates html code, and displays it in a textarea with submit button. I want to submit button to take the data entered in that textarea1 on page 1, and upload to textarea2 on page 2 How can I do this? I have no idea where to start. I'm trying to create a INSERT query statement that makes use of the content of 'include' files. When I call up the include it simply echos it to the screen but I can't seem to capture the text string and actually make it function as part of the query. I've tried setting the include as a variable but again it only outputs to the screen. Help please! Here's a portion of the code... if (($_POST['sched_templates']) == "sched_TestingOnly.htm") { $query = include 'sched_TestingOnlyQuery1.htm'; } if (@mysql_query ($query)) { mysql_close(); // End adding Registration to the database header ('Location: redirectfile.htm'); exit(); } else { print "<p><b>Sorry, your entry could not be entered. } Hey guys I m developing a download system for my server that reads files from a third party server and enables MY USER to download it via my URL. What mechanisms should i use to manage this efficiently ??? file_get_contents(); fopen(); Or should I use some kind of buffer mechanism ??? Please do provide a code sample as I'm stuck here very badly. Note: The file sizes may be >500MB How to do it? I have read some methods but they seem to not work. This is what I have got so far:
<?php Hi
I try to echo out random lines of a html file and want after submit password to whole content of the same html file. I have two Problems.
1st Problem When I echo out the random lines of the html file I don't get just the text but the code of the html file as well. I don't want that. I just want the text. How to do that?
for($x = 1;$x<=40;$x++) { $lines = file("$filename.html"); echo $lines[rand(0, count($lines)-1)]."<br>"; }I tried instead of "file("$filename.html");" "readfile("$filename.html");" But then I get the random lines plus the whole content. Is there anything else I can use instead of file so that I get the random lines of text without the html code?P.S file_get_contents doesn't work either have tried that one. 2nd Problem: As you could see in my first problem I have a file called $filename.html. After I submit the value of a password I want the whole content. But it is like the program did forget what $filename.html is. How can I make the program remember what $filename.html is? Or with other words how to get the whole content of the html file? My code: if($_POST['submitPasswordIT']){ if ($_POST['passIT']== $password ){ $my_file = file_get_contents("$filename.html"); echo $my_file; } else{ echo "You entered wrong password"; } }If the password isn't correct I get: You entered wrong password. If the password is correct I get nothing. I probably need to create a path to the file "$filename.html", but I don't know exactly how to do that. |