I have a small problem with my php code. Please take a look:
<?php
$urlud = $json['url'];
$content = 'Content 1 if file no exist will generate';
$filename = $json['id'].".html";
if (file_exists($filename)) {
echo "File exists!";
} else {
file_put_contents('dir1/'. $filename, $content, FILE_APPEND | LOCK_EX);
}
?>
<?php
$urlud = $json['url'];
$content = 'Content 2 if file no exist will generate';
$filename = $json['id'].".html";
if (file_exists($filename)) {
echo "File exists!";
} else {
file_put_contents('dir2/'. $filename, $content, FILE_APPEND | LOCK_EX);
}
?>
This code will generate 2 files in different directories with different content. My problem is:
- This code keeps replacing my old file content. Any solution to make it create only if the file doesn't exist ?
- Any other input to make this code simpler?
Thanks.
$filename $stringand$stringwill be unique everytime