ralphi91 Posted August 26, 2007 Share Posted August 26, 2007 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?> Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/ Share on other sites More sharing options...
tibberous Posted August 26, 2007 Share Posted August 26, 2007 Your missing a double-quote: $stringData = "$text; Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334268 Share on other sites More sharing options...
matthewhaworth Posted August 26, 2007 Share Posted August 26, 2007 Your missing a double-quote: $stringData = "$text; To be honest, I wouldn't use the double quote at all. Also, you're not really asking us for anything, unless the error was what you were after.. Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334269 Share on other sites More sharing options...
ralphi91 Posted August 26, 2007 Author Share Posted August 26, 2007 well i need some tips and hints on what to go to next or something at least Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334273 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334286 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 If your interested I have an ajax based notepad type deal that stores in mysql. Be more than happy to give ya the code if you want It uses an onchange event trigger so there is no buttons to mess with. If it suits your need, lemme know and I will let ya have it. Nate Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334308 Share on other sites More sharing options...
ralphi91 Posted August 26, 2007 Author Share Posted August 26, 2007 An Error Has Occurred! You are not allowed to send personal messages. yeah hit us up with that one, sounds more professional than the one i have at the moment. Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334366 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 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] Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334378 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 #2 The main file is header.php, I forgot to change the name of it to index.php or something relevant .... oops hope ya dig it [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334379 Share on other sites More sharing options...
ralphi91 Posted August 26, 2007 Author Share Posted August 26, 2007 thanks for that, it works perfectly. now to password protect the notes? Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334382 Share on other sites More sharing options...
chronister Posted August 26, 2007 Share Posted August 26, 2007 Either .htaccess/.htpasswd or a custom built user system Glad ya like it. Nate Quote Link to comment https://forums.phpfreaks.com/topic/66715-php-notepad/#findComment-334389 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.