Why can’t i write data to files with PHP on Vercel

  php, vercel

I wanted to store some data on Vercel with PHP but i can’t write anything. Here’s the Code:

<!DOCTYPE html><html><head></head><body>
<?php
if(file_exists("write_webcounter.php"))
{
$fp = @fopen("write_webcounter.php", "r");
if($fp)
{
$number = fgets($fb, 10);
$fclose($fp);
}
else
  $number = 0;
}
else
  $number = 0;

$number = $number + 1;
echo "Webcounter: $number";

$fp = @fopen("write_webcounter.txt", "w");
if(!$fp)
  exit("Webcounter could not be written");

fputs($fp, $number);
fclose($fp);
?>
</body></html>

It always says: Webcounter could not be written.

Source: Ask PHP

LEAVE A COMMENT