rcpopart Posted October 18, 2007 Share Posted October 18, 2007 Absolute NEWBIE to PHP. I've got this piece of PHP code on one site (server) and it works fine with the other 2 files. I've copied the exact same files to another server and it doesn't work. everything in all the files are relative paths and I don't understand why it's not working. I've checked with the hosting provider and they tell me that PHP is enabled on the second account, but it's still not working even with exact duplicate files. I'm wondering if it's because the second server is running on PHP5. I'm not sure what the first server is running, but could that be causing the problem? What would you suggest I do? HELP! <?php function myurlencode($text) { $text = str_replace("%", "%25", $text); $text = str_replace("&", "%26", $text); return $text; } $data = "textfile.txt"; // make sure it has 666 permissions $fp = fopen($data, "window2="); fwrite($fp, "window2=" . myurlencode(stripslashes($input))); fclose($fp); echo "status=Done"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/ Share on other sites More sharing options...
Orio Posted October 18, 2007 Share Posted October 18, 2007 Check if these files have the appropriate permissions to be written. (CHMOD) Orio. Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372706 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 If I had to guess I'd say it's because you might be specifying an improper 2nd argument to fopen(): $fp = fopen($data, "window2="); Why don't you try testing the value of $fp to see if fopen() succeeds? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372707 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 thanks, guys. how exactly do I do those things? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372709 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 <?php function myurlencode($text) { $text = str_replace("%", "%25", $text); $text = str_replace("&", "%26", $text); return $text; } $data = "textfile.txt"; // make sure it has 666 permissions $fp = fopen($data, "window2="); if(!$fp){ die("Error: Unable to open file"); } fwrite($fp, "window2=" . myurlencode(stripslashes($input))); fclose($fp); echo "status=Done"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372712 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 sweet. thanks so much, I'm going to upload it and try it out. be back soon! Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372714 Share on other sites More sharing options...
Daukan Posted October 18, 2007 Share Posted October 18, 2007 Shouldn't fopen use the 'w' flag for writing? what is "window2="? $fp = fopen($data, 'w') Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372718 Share on other sites More sharing options...
lewis987 Posted October 18, 2007 Share Posted October 18, 2007 Same thoughts daukan, isnt it meant to be 'w' than 'window2='? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372721 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 Okay, I've uploaded this code onto the server: <?php function myurlencode($text) { $text = str_replace("%", "%25", $text); $text = str_replace("&", "%26", $text); return $text; } $data = "textfile.txt"; // make sure it has 666 permissions $fp = fopen($data, 'w') if(!$fp){ die("Error: Unable to open file"); } fwrite($fp, "window2=" . myurlencode(stripslashes($input))); fclose($fp); echo "status=Done"; ?> my .txt file is still blank. Nothing is being written to it. Can you suggest another way it should be written fellas? I really appreciate your patience. Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372730 Share on other sites More sharing options...
kellz Posted October 18, 2007 Share Posted October 18, 2007 what is "window2=" supposed to be? ??? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372733 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 Are you getting any sort of output? Are you seeing your "status=Done" message? You are writing $input to the file but I don't see $input defined anywhere; are you sure the variable contains anything inside it? Insert this into the script: echo "input len: " . strlen($input); Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372734 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 I have a .swf file with an input window (variable: input) with this code attached to the button: on (release) { loadVariables("write.php", "_level0", "POST"); } on (release) { input = ""; } Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372739 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 Ok. But that still doesn't tell what is in your $input variable when your PHP script runs. Also, since you said this is coming from a .swf file, are you sure the .swf file is sending it to the correct server? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372743 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 $input variable is a input text window for the user to type in, with a "enter" button below it. located here: http://www.johnwasem.com/write.swf the enter button has this actionscript attached to it: on (release) { loadVariables("write.php", "_level0", "POST"); } on (release) { input = ""; } the text (whatever the person writes in the input window) is then sent to the php script (write.php), which then prints the exact same words in a .txt file called "textfile.txt" with the phrase - "window2=" before it. For example, when someone types "hey. how's it going." in the .swf input window, the output on the .txt file will be: "window2=hey. how's it going." does this make sense? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372753 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 Yah, I understand how the whole thing works. But did you confirm that the data was sent correctly? Try and echo the contents of your $input variable in the script that's writing the file. Basically, everything your script looks correct and you should be getting some output into your file. You still never answered this question: Are you seeing your "status=Done" message? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372762 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 So when I go directly to your script: http://www.johnwasem.com/write.php I get this: Parse error: syntax error, unexpected T_IF in C:\Sites\Single8\jwasem\webroot\write.php on line 10 You forgot a semi-colon after your fopen() statement. Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372764 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 fixed it. still not writing to my .txt file. Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372773 Share on other sites More sharing options...
roopurt18 Posted October 18, 2007 Share Posted October 18, 2007 If you visit the PHP script directly in your browser using the URL below, you see an error: http://www.johnwasem.com/write.php Error: Warning: fopen(textfile.txt) [function.fopen]: failed to open stream: Permission denied in C:\Sites\Single8\jwasem\webroot\write.php on line 8 Error: Unable to open file So now you're back to what Orio started out by saying, do your PHP scripts have write access to this directory? Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372780 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 probably not. does that mean that I can't do this? it's brinkster.com Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372785 Share on other sites More sharing options...
rcpopart Posted October 18, 2007 Author Share Posted October 18, 2007 Thank you so much roopurt18, I've contacted the hosting provider and indeed i needed the write permissions set. that was the problem. I hadn't come across this before. Now I know. stupid newbie. Quote Link to comment https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/#findComment-372796 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.