| |||||||||||
write to text file with php Posted by eliddell (eliddell), 12 June 2005 hi.... I have no clue what i am doing... but i know its possible..i have a flash page that loads text from a text file. the text file simple looks like this &variable1="text" &variable2="text" &variable3="text" you get the point.. i would like to creat an html page that loads these same variables into three input text fields and allows the user to change the text for each variable then re-write the text file so it reads &variable1="changed text" &variable2="changed text" &variable3="changed text" who wants to help me with creating the html page and the php file that re-writes the text file. pretty please. erik Posted by admin (Graham Ellis), 13 June 2005 Hi, Erik, and welcome here. As you'll see from the title of this board, we're really here to help you learn to program rather than provide a "please write this code for me" service - however, what you're looking for is quite possible in a couple of hours for a fast and experienced programmer and someone may take your request up. Are you prepared to make any form of payment for getting the program written?There are other alternatives - there's lots of good sample code out there that you could adopt and adapt. Indeed, I'm struck that our tiny talker example at http://www.wellho.net/resources/ex.php4?item=h109/saver.php4 provides an example that reads and updates a file on the fly from a form. You would need to add a fair chunk of string handling - see http://www.wellho.net/resources/H107.html for some samples. Books ... we have 58 on PHP, including 7 for absolute beginners - browse the text of the sleeves from those links to help find which suits you. If you get stuck with a specific coding issue, to post an illustration of the problem you're having to the PHP board here and we'll help you over that hurdle. And (yet another option). There's some good training courses out there. Ours run in Melksham, Wiltshire, UK ... and there are other available elsewhere in the world. If you're seriously wanting to get into PHP programming, that's an excellent way to do so, since you learn not only the mechanics but also the best way to make use of PHP and cover wider issues like writing code that's easy to maintain, and also you'll pick up a load of adivise about writing secure and robust applications. Hope that gives you some pointers ... please do follow up and let us know which route you choose / how you get on. Posted by Chris_Isaac (Chris Isaac), 13 June 2005 HiI can recommend the PHP in Easy Steps book, easy to follow, and I still use it as a reference now. Also PHP and MySQL Web Development is an excellent book to learn from. If you can go for a proper course, I've sat on Graham's PHP course and its excellent. Posted by eliddell (eliddell), 14 June 2005 Thanks guys... actually before i even got a reply from you all ifigured it out.. i actually used flash and php.. the php (though it was my first php script) was a lot simpler than the flash that post to it... all because i needed the text file to have each variable seperated with an "&variablename=" so that the flash movie could read it properly... so the solution was to have the flash movie take all the variables and create one new variable with the (&variable=) inserted... and then the php just wrote one variable to the text file... i am posting it for others to see if intrested here is the action script i used on the submit button: on (press){ set ("newduo",_root.newduo.text); set ("new357",_root.new357.text); set ("newphinelia",_root.newphinelia.text); set ("newwhatsup",_root.newwhatsup.text); set ("newmusic",_root.newmusic.text); set ("newproduct",_root.newproduct.text); set ("newcontact",_root.newcontact.text); set ("newcontent", "&duo=" + newduo + "&357=" + new357 + "&phinelia=" + newphinelia + "&whatsup=" + newwhatsup + "&music=" + newmusic + "&product=" + newproduct + "&contact=" + newcontact + "&"); } on (release){ getURL("write.php",_self,"POST") } here is the php: <?php $myFile = "text.txt"; $fh = fopen($myFile, 'w') or die("can't open file"); echo "changes have been submited"; fwrite($fh, $newcontent); fclose($fh); ?> Posted by eliddell (eliddell), 14 June 2005 btw this was all so i could build a basic content manager for a flash site...that site being http://357phinelia.com check it out and tell me what you think Posted by admin (Graham Ellis), 14 June 2005 Thanks for the follow up. Glad you're sorted.With scripting like this, it's very important to not only have it working, but also to incorporate error and security checking. I don't know enough about flash and actionscript to make specific comments on your solution, but I do hope you've considered how your script / system will handle malicious inputs such as pieces of code and tags entered into the form boxes .... Posted by eliddell (eliddell), 15 June 2005 the php code i used above - for what ever reason ads a back slash any time you submit text with a " or a ' is there anyway around that? Posted by admin (Graham Ellis), 15 June 2005 Your server is running with "magic quotes" on. If you're the server admin and want to turn this feature off for all your scripts, you can use do so using: magic_quote_gpc = off in your php.ini file. This setting can also be made via your httpd.conf file and .htaccess files using php_flag magic_quotes_gpc off If you're not the server admin and want to make the change just on the $newcontent variable, you could include in your code $newcontent = stripslashes($newcontent); I note that you're using $newcontent rather than $_POST[newcontent] as your script input (and you tell us that your code works). This implies that you're working with an older version of PHP, or that your server is running with the register_globals initialisation variable switch to on, which is not the default. If you're working with PHP 4.1.0 or later, I suggest that you add the extra line $newcontent = stripslashes($_POST[newcontent]); at the top of your script which will cure the problem that you reported and will make your code more portable. Posted by eliddell (eliddell), 15 June 2005 can i call you golden graham?you fucking rock.. thanks for helping the newbie... i even figured out how to check for a password so that no one accidently calls the php without going through the form that i made and there by accidently erasing all content.. wow i learnt quite a bit in two days about php.. its pretty simple stuff once you get the sintax and commands down.. oh and on the malicious code entered into the form boxes in flash.. 1. you can't get to the form with out a pass word and 2. even if you did the fields are not set up to rebder as code only "text" so i believe i am all set.. thanks again This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |