How can the issue of images being overwritten with new images of the same name be prevented in PHP?

To prevent images from being overwritten with new images of the same name in PHP, you can append a timestamp to the image file name before saving it. This way, each image will have a unique name and avoid conflicts.

// Generate a unique file name by appending a timestamp
$timestamp = time();
$imageName = $timestamp . '_' . $_FILES['image']['name'];

// Save the image with the unique file name
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/' . $imageName);