Php Edit - Slightly Confused!?

james150687

New member
So i've come across this code:

<?php
class SafeWriter
{
// suggested mode 'a' for writing to the end of the file
public static function writeData($path, $mode, $data)
{
$fp = fopen($path, $mode);
$retries = 0;
$max_retries = 100;

if (!$fp) {
// failure
return false;
}

// keep trying to get a lock as long as possible
do {
if ($retries > 0) {
usleep(rand(1, 10000));
}
$retries += 1;
} while (!flock($fp, LOCK_EX) and $retries <= $max_retries);

// couldn't get the lock, give up
if ($retries == $max_retries) {
// failure
return false;
}

// got the lock, write the data
fwrite($fp, "$data\n");
// release the lock
flock($fp, LOCK_UN);
fclose($fp);
// success
return true;
}
}
?>

How would I implement the code below into that so it would work?

<?php


$total = $_POST['buyLink'];
$myFile = "buyLink.txt";
unlink($myFile);
$open = fopen($myFile, 'a+');
$write = fwrite($open, '&buyLink=' . $total+=1);
if($write)
{
echo "&verify=success&";
}
else
{
echo "&verify=fail&";
}

?>




Thanks guys
 
Back
Top