Jump to content

php notepad


ralphi91

Recommended Posts

i would like to make a notepad to save and load things from a text file stored on my webserver. I would like to have 3 buttons, "save", "load" and "refresh".

 

I am not good with php and i have found the following parts of code that would probably be useful in creating this.

 

<?php
$myFile = "71637213418#$%.txt";

$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "$text;
fwrite($fh, $stringData);
$stringData = "----";
fwrite($fh, $stringData);
fclose($fh);//sending

php?>

Link to comment
Share on other sites

I wrote some code for you, which actually reads a hard coded file and displays it in a textarea. There is only a save button right now, but if u know two things in php u should modify it for your needs. If u cant then tell and i'll add also the load button.

 

<?php
//open the file and read it contents
$file = 'text.txt';
$handle = fopen($file, 'r');
$text = fread($handle, filesize($file));
fclose($handle);
?>
<form name="form1" method="post" action="">
  <textarea name="textarea" cols="50" rows="10"><?php echo $text; ?></textarea>
  <input type="submit" name="Submit" value="Save" />
</form>
<?php
//if post data are submited then open the file and overwrite the text
if(array_key_exists('textarea', $_POST)){
$text = $_POST['textarea'];
$handleW = fopen($file, 'w+');
fwrite($handleW, $text);
fclose($handleW);
echo "File was saved successfully";
echo "<meta http-equiv=refresh content=\"1; url=index.php\">"; //just a refresh
}
?>

Link to comment
Share on other sites

Here ya go, this works as is. All ya need to do is create the db and set your db info in the functions file. Unfortunately the drawback with this script is that you can only have 1 record in the table and it's id is hardcoded as 1, but it's not a real big deal.

 

This also has a javascript expander function attached to it. If the text in the box is too long so a scroll bar is seen, once you click in the box it expands to fit the text. Pretty handy. I grabbed the expander function from I don't know where, the AJAX script came from this site in the tutorials and the rest I put together myself.

 

All paths are set for all files in the same directory, but you can change that if you want. There is one gif image that is used. It's path is set to /images/loading.gif

 

Gonna have to do this in a couple posts. I am attaching the files because there is too much code to post. Remove the .txt extension from the files as .js & .php are not allowed.

 

[attachment deleted by admin]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.