What are the potential pitfalls of using wildcards in file paths when downloading images with PHP?

Using wildcards in file paths when downloading images with PHP can be risky as it can potentially lead to security vulnerabilities such as directory traversal attacks. To avoid this, it is recommended to explicitly specify the exact file path when downloading images.

// Specify the exact file path when downloading images
$imageUrl = 'https://example.com/images/image1.jpg';
$imagePath = '/path/to/save/image1.jpg';

// Download the image
file_put_contents($imagePath, file_get_contents($imageUrl));