Jump to content

Recommended Posts

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"; 
?> 



Link to comment
https://forums.phpfreaks.com/topic/73869-writing-to-txt-file-simple-right/
Share on other sites

<?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"; 
?> 

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.

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);

$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?

 

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?

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.

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?

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.