I've got a PHP Script that creates a txt file using a form and saves it under the filename "businesscard-1.txt". If i gonna run the Script again it overrides the "businesscard-1.txt" with the new data. But i want it to create a new file with the name "businesscard-2.txt" and if this exists too, than it should get the name "businesscard-3.txt" etc. Does anyone know how to do that ?
<?php
$part1 = $_POST["Imputfield-1"];
$part2 = $_POST["Imputfield-2"];
$part3 = $_POST["Imputfield-3"];
$file = fopen('businesscard-1.txt', 'w+');
ftruncate($file, 0);
$content =
$part1. PHP_EOL .
$part2. PHP_EOL .
$part3. PHP_EOL ;
fwrite($file , $content);
fclose($file );
header("Location: Page2.htm");
die();
?>