What are the potential pitfalls of using hardcoded URLs in PHP code for file operations, especially when moving between different servers?

Hardcoding URLs in PHP code for file operations can lead to issues when moving between different servers, as the hardcoded URLs may not be valid on the new server. To avoid this, it is recommended to use relative paths or dynamically generate the URLs based on the server environment.

// Example of dynamically generating a file path based on the server environment
$server = $_SERVER['SERVER_NAME'];
if($server == 'example.com') {
    $file_path = '/var/www/html/uploads/';
} else {
    $file_path = '/home/user/public_html/uploads/';
}