What potential issues can arise when renaming uploaded images in PHP?

When renaming uploaded images in PHP, potential issues can arise if the new filename already exists, leading to overwriting existing files or causing conflicts. To avoid this, it is recommended to generate a unique filename for each uploaded image by appending a timestamp or a random string to the original filename.

// Generate a unique filename for the uploaded image
$originalFilename = $_FILES['image']['name'];
$extension = pathinfo($originalFilename, PATHINFO_EXTENSION);
$uniqueFilename = uniqid() . '.' . $extension;

// Move the uploaded image to the desired directory with the unique filename
move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/' . $uniqueFilename);