What potential error could occur when trying to generate a random number for file naming in PHP?
When generating a random number for file naming in PHP, a potential error could occur if the same random number is generated more than once, leading to overwriting existing files. To solve this issue, you can use a combination of timestamp and a random number to ensure uniqueness in file names.
// Generate a unique filename using timestamp and random number
$filename = time() . '_' . mt_rand(1000, 9999) . '.txt';
// Use the generated filename for file operations
file_put_contents($filename, 'File content goes here');