Log in

View Full Version : Overwriting a txt file using php and ftp.



josephtaylor1995
04-05-2009, 10:16 AM
Hi, I'm a noob at php and other coding stuff so i need a little help.

What I am trying to achieve is: a textarea with a submit button, and when you click the submit button it edits/overwrites a file in my server.

If you need more info, please contact me, thanks,
Joseph

tfit
04-05-2009, 06:15 PM
Hi, I'm a noob at php and other coding stuff so i need a little help.

What I am trying to achieve is: a textarea with a submit button, and when you click the submit button it edits/overwrites a file in my server.

If you need more info, please contact me, thanks,
Joseph

maybe this is useful


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">
textarea {
font-size:11px;
font-family:"Courier New", Courier, mono;
}
</style>
</head>
<body>
<?php

if(isset($_POST['submit'])) {
$content = $_POST['contents'];
$file = fopen("script.txt", "w");
fwrite($file, $content);
fclose($file);
}
?>

<h1>Alter TEXT File</h1>
<form name="edit" method="post">
<textarea name="contents" cols="80" rows="23">
<?php
$file = "script.txt";
$open = fopen($file, "r");
$size = filesize($file);
$count = fread($open, $size);

echo($count);
?>
</textarea><br />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

josephtaylor1995
04-05-2009, 07:34 PM
thanks ive been looking all day for a script like this, did you make it or did you get it off a side? what site did you get it off if you did? thanks again :)

tfit
04-06-2009, 08:21 AM
I am afraid I'll have to disappoint you. It's sample code of php.net.
OT: I did some extreme DIY the last few months and got really annoyed with open/unclosed threads. So, if your question is answered please push it to resolved. Thanks in advance