legohead6 Posted July 10, 2006 Share Posted July 10, 2006 Ok I have a code that you can edit text files you upload and then you can save it but for some reason its all weird(first time using fwrite()) it has the '>' before the original text and when i remove everything text and that thing it doesnt erase the page! also when i add something it like only shows the first letter or it shows up 5 times! Please give me an fwite code that take exactly how the textarea is and make it what the page looks like! Please sumthing simple as this is more of a learning project for me! Quote Link to comment https://forums.phpfreaks.com/topic/14145-fwrite-screwy/ Share on other sites More sharing options...
Daniel0 Posted July 10, 2006 Share Posted July 10, 2006 This script should save a file: [code]<?phpecho <<<EOF<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>File writer</title><style type='text/css'>body{ text-align: center;}body, input{ font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 80%;}input, textarea{ border: 1px solid black; width: 100%;}textarea{ font-size: 90%; font-family: "Courier New", Courier, mono-spaced;}#form{ width: 500px; padding: 0px; margin: auto; text-align: left;}#form.buttonstrip{ text-align: center; margin: auto;}#form label{ font-weight: bold;}</style></head><body><h1>File writer</h1>EOF;$dir = "/var/www/stuff/";if(!empty($_POST['content']) && !empty($_POST['filename'])){ chdir($dir); if(file_exists($filename)) { echo "Sorry, that file already exists"; } else { $fp = fopen($_POST['filename'],'w'); fwrite($fp,$_POST['content']); fclose($fp); echo "<p>The file has been saved.<br /><a href='javascript:history.go(-1)'>Back</a></p>"; }}else { echo <<<EOF<div id='form'><form action='{$_SERVER['REQUEST_URI']}' method='post'><label for='filename'>Filename:</label><br /><input type='text' name='filename' id='filename' accesskey='F' /><br /><label for='content'>Content:</label><br /><textarea rows='15' cols='50' name='content' id='content' accesskey='C'></textarea><button type='submit' accesskey='S'>Save</button> <button type='reset' accesskey='R'>Reset</button></form></div>EOF;}echo <<<EOF</body></html>EOF;?>[/code][b]Note:[/b] It is NOT secured, you need to make sure that the user won't save stuff outside of the directory if you don't trust them. Quote Link to comment https://forums.phpfreaks.com/topic/14145-fwrite-screwy/#findComment-55418 Share on other sites More sharing options...
legohead6 Posted July 10, 2006 Author Share Posted July 10, 2006 Ya but how do i make the edit thing! where the current content shows up in a textarea and whatever you change in ther it changes to the page erasing or adding new stuff Quote Link to comment https://forums.phpfreaks.com/topic/14145-fwrite-screwy/#findComment-55603 Share on other sites More sharing options...
Ninjakreborn Posted July 10, 2006 Share Posted July 10, 2006 He just showed you. Quote Link to comment https://forums.phpfreaks.com/topic/14145-fwrite-screwy/#findComment-55623 Share on other sites More sharing options...
legohead6 Posted July 10, 2006 Author Share Posted July 10, 2006 his code creates a new file!( witch came in handy) i need one to edit existing files Quote Link to comment https://forums.phpfreaks.com/topic/14145-fwrite-screwy/#findComment-55651 Share on other sites More sharing options...
Daniel0 Posted July 10, 2006 Share Posted July 10, 2006 Remove the part that checks if the file exists and load the content of the file into the script by using fopen() along with fread() or file_get_contents() and echo it between the textarea tags. Quote Link to comment https://forums.phpfreaks.com/topic/14145-fwrite-screwy/#findComment-55692 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.