LO QUE ENTIENDO ES QUE PRIMERO QUIERES IDENTIFICAR QUE EXTENCION TIENE AL ARCHIVO $id ... I DESPUES IMPRIMIRLO DEPENDIENDO QUE ESTENCION TENGA..
SI ESTO ES CORRECTO.. SE HACE ASI
Código PHP:
if (file_exists("imagen/".$id.".jpg")) {
$foto1="imagen/".$id.".jpg";
} elseif (file_exists("imagen/".$id.".pdf")) {
$foto1="imagen/".$id.".pdf";
} elseif (file_exists("imagen/".$id.".doc")) {
$foto1="imagen/".$id.".doc";
} elseif (file_exists("imagen/".$id.".xls")) {
$foto1="imagen/".$id.".xls";
} elseif (file_exists("imagen/".$id.".ppt")) {
$foto1="imagen/".$id.".ppt";
};
$img="paginas/".$id.".jpg";
if (file_exists($foto1) and $foto1==$img){
$n="";
$s="<img src=".$foto1." height='111' width='147'/>";
}
elseif (file_exists($foto1) and $foto1!=$img){
$n="";
$s=$foto1;}