What are some common methods for handling image uploads and paths in PHP within a WordPress environment?

When handling image uploads in PHP within a WordPress environment, it is important to properly manage file paths to ensure the images are stored and accessed correctly. One common method is to use the WordPress function `wp_upload_dir()` to get the upload directory path and URL. This function returns an array containing the path and URL for the uploads directory, which can be used to save and retrieve image files.

// Get the upload directory path and URL
$upload_dir = wp_upload_dir();

// Set the file path for the uploaded image
$file_path = $upload_dir['path'] . '/' . basename( $_FILES['image']['name'] );

// Move the uploaded image to the uploads directory
move_uploaded_file( $_FILES['image']['tmp_name'], $file_path );

// Get the URL for the uploaded image
$image_url = $upload_dir['url'] . '/' . basename( $_FILES['image']['name'] );

// Use $file_path and $image_url as needed for further processing