gorilla1
09-19-2002, 11:41 PM
I am running the code below on phpdev. If I leave out the lock logic, the file gets written. However, with the lock logic, it does not. I tried fputs, too, and no success. Can anyone spot where I have erred?
G
$fp = fopen('emails.txt','a');
$lock = flock($fp, LOCK_EX);
if($lock){
$emailsize = strlen($email . "\n");
$fw = fwrite($fp, $email . "\n", $emailsize);
if ($fw)
echo "<b><div align=center>$email has been added to the subscriber list.</div></b>";
else
echo "Error!";
flock($fp, LOCK_UN);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
}
G
$fp = fopen('emails.txt','a');
$lock = flock($fp, LOCK_EX);
if($lock){
$emailsize = strlen($email . "\n");
$fw = fwrite($fp, $email . "\n", $emailsize);
if ($fw)
echo "<b><div align=center>$email has been added to the subscriber list.</div></b>";
else
echo "Error!";
flock($fp, LOCK_UN);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
}