Is there any reason why you can't just pass the extension along as well? If it's only going to be a matter of jpg or php files, I'd do:
Code:
$id = $_REQUEST['id'];
if(file_exists($id.".jpg")) {
echo "<img src='$id.jpg'>";
} elseif(file_exists($id.".php")) {
include($id.".php");
} else {
include("main.php");
}