...

View Full Version : Writing to a text file bombing out.



ajetrumpet
11-05-2009, 06:14 PM
all,

I have two site with distinctly identical coding behind a page. it is this on my unsubscribe page:
<?php
if (! $_POST["email"] || strlen($_POST["email"]) == 0 || strpos($_POST["email"], "@") == 0)
{
//DO NOTHING
}
else {
$handle = @fopen("../logs/unsubscribes.txt", "a");
fputs($handle, $_POST["email"] . " " . "\r\n");
fclose ($handle);

echo 'Thank you, you have been unsubscribed';
exit; }
?>


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my page</title>

<script type="text/javascript">
<!--
function validateForm(form)
{
var emRE = /^[\w\-\'\.]+\@([\w\-\']+\.)+[a-z]{2,6}$/i;
if ( ! emRE.test( form.email.value ) )
{
alert("Please enter a valid email address");
return false;
}
return true;
}
//-->
</script>

</head>

<body>

<form action="" method="post" name="frm" onsubmit="validateForm(this)">

<center><br />
Enter Your Email Address:<br />
<input type="text" id="email" name="email" />
</center>
<p>
<label>
<center><input type="submit" id="unsubscribe" value="Unsubscribe Me" /></center>
</label>
</p>
</form>

</body>
</html>on one of my websites, this works perfectly, and on the smaller one, the PHP at the top throws an "invalid stream resource" error at me. I assume the stream is the text file I am writing to. There is the same error occuring on two lines. One is fputs() and the other is fclose(). I know the text file is in the right place and the syntax for locating it is also correct. Can someon identify a problem here please? thanks for any help!

oesxyl
11-05-2009, 06:23 PM
check $handle to be valid before you use it, also check permission and see if fopen and friend are not disabled. If still don't work, check path and file again.
I would remove @ to see what fopen say about this, :)

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum