What is the potential issue with using a fixed filename like "test.jpg" for uploaded images in PHP?

Using a fixed filename like "test.jpg" for uploaded images in PHP can lead to overwriting existing files or potential conflicts when multiple users upload files with the same name. To solve this issue, it is recommended to generate a unique filename for each uploaded image. This can be achieved by appending a timestamp or a randomly generated string to the filename.

// Generate a unique filename for the uploaded image
$filename = uniqid() . '_' . $_FILES['file']['name'];
$targetPath = 'uploads/' . $filename;

// Move the uploaded file to the desired location with the unique filename
move_uploaded_file($_FILES['file']['tmp_name'], $targetPath);