Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/02/2011, 03:14
gamuba
 
Fecha de Ingreso: marzo-2010
Mensajes: 12
Antigüedad: 14 años, 1 mes
Puntos: 0
PHP solo muestra codigo fuente

Buenas a todos
Tengo un gestor de noticias que corría perfectamente en IE7, y al instalar IE8 cascó.
Tengo un fichero llamado noticias que abre perfectamente y desde el cual tengo la posibilidad de gestionar las noticias, nuevas, modificar, eliminar mediante
<input name="button" type="button" onClick="abreVentana('<?=$SIGUIENTE?>?val=nueva',' ',650,430,true);" value="Nuevo">. Al pulsar este en lugar de abrir una nueva página como hacia antes, me muestra el código fuente.
Aquí dejo el código que se muestra.

<?php
include("./includes/config.php");
include("./includes/funciones.php");
include("./includes/checklogin.php");
header("Content-type: image/jpeg");

//PARAMETROS DE CONFIGURACIÓN************
$val=$_GET['val'];
$CARP_FOTOS="./fotos/";
$TABLA="noticias";
$CAMPO_ID="id";
$ANTERIOR="noticia_g.php";
//***************************************

if ($HTTP_POST_VARS){
$imgpathfotos=$CARP_FOTOS;
$mensaje="";
//Si he asignado una foto la subo al servidor para despues asignarla
$error2=false;
if ((isset($_FILES['foto'])) && ($_FILES['foto']['tmp_name']!="")){
//SUBIR FOTO
if (is_uploaded_file($_FILES['foto']['tmp_name'])) {
//$error2=false; la inicializo arriba de if
//echo $_FILES['imagen']['type'];
//revisamos el tipo de la imagen
$nombre = $_FILES['foto']['tmp_name'];
$punto = strrchr($nombre,".");
if ($_FILES['foto']['type'] == "image/jpeg" || $_FILES['foto']['type'] == "image/pjpeg"){
$newFoto = "foto".time().".jpg";
}else if ($_FILES['foto']['type'] == "image/bmp"){
$newFoto = "foto".time().".bmp";
}else if ($_FILES['foto']['type'] == "image/x-png"){
$newFoto = "foto".time().".png";
}else if ($_FILES['foto']['type'] == "image/gif"){
$newFoto = "foto".time().".gif";
}else if ($nombre[$punto+1]=="j" && $nombre[$punto+2] == "p" && $nombre[$punto+3] == "g" ){
$newFoto = "foto".time().".jpg";
}else{
$error2=true;
$mensaje= " · Formato no válido de fotografía: " . $_FILES['foto']['name']." (Debe ser gif, bmp, png o jpg)-----".$_FILES['foto']['type'];
};
if (!$error2){
if(!copy($_FILES['foto']['tmp_name'], $imgpathfotos.$newFoto)){
// no se puedo subir :S
$error2=true;
$mensaje= " · Error al cargar fotografía: " . $_FILES['foto']['name'];
}else{
chmod($imgpathfotos.$newFoto,0777);
}
}
} else {
if($_FILES['foto']['name'] == ""){
//$error2=true;
$error2=true;
}else{
$error2=true;
$mensaje= " · Error al cargar la fotografía porque tiene un tamaño muy grande: " . $_FILES['foto']['name'];
}
}//fin subir foto
}//fin comprobar si tengo que subir foto
if ($error2){
$_POST['foto']="";
}else{
$_POST['foto']=$newFoto;
}
$cnx = conectar();
$querySel = "SELECT id FROM ".$TABLA." WHERE ".$CAMPO_ID."='".$_POST['id']."'";
$query= mysql_query($querySel) or die(mysql_error());
$numfilas= mysql_num_rows($query);
//preparo textos
$_POST['titulo']= str_replace ("'", "´", $_POST['titulo']);
$_POST['texto']= str_replace ("'", "´", $_POST['texto']);
if ($numfilas>0)
{
// en UPDATE nunca vamos a modificar la foto
$queryUpd = "UPDATE ".$TABLA." SET titulo='".$_POST['titulo']."',texto='".$_POST['texto']."' WHERE ".$CAMPO_ID."='".$_POST['id']."'";
$query= mysql_query($queryUpd) or die(mysql_error());
if (!$query){
$Fallo=true;
}
}
else
{
if (!isset($_POST['foto'])){
$_POST['foto']="";
}
//en INSERT siempre llegara la foto, aunque sea como cadena vacia
$queryIns = "INSERT INTO ".$TABLA." (titulo,texto,foto) VALUES ('".$_POST['titulo']."','".$_POST['texto']."','".$_POST['foto']."')";
$query= mysql_query($queryIns) or die(mysql_error());
if (!$query){
$Fallo=true;
}
}
if (!$Fallo){

}else
{
?><script>alert('Se ha producido un error en la Base de Datos\nLos Cambios no se harán efectivos\n');</script><?php
}
if ($error2){
echo "<script>alert('Error en la Fotografía:\n".$mensaje."');</script>";
}
echo "<script>window.opener.location.href='".$ANTERIOR. "';";
echo "window.close();</script>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta name="GENERATOR" content="PHPEclipse 1.0" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>..:: Gesti&oacute;n ::..</title>
<link href="estilos.css" rel="stylesheet" type="text/css">
<SCRIPT LANGUAGE='JavaScript'>

function testAllFields(){
if (document.datos.titulo_es.value=="" ){
alert('Debe escribir el/los apellido/s del Autor.');
document.datos.apellidos.focus();
return false;
}
return true;
}//cierra return testAll fields
function cancela()
{
window.opener.location;
window.close();
}
function Validar(Cadena){
var Fecha= new String(Cadena) // Crea un string
var RealFecha= new Date() // Para sacar la fecha de hoy
// Cadena Año
var Ano= new String(Fecha.substring(Fecha.lastIndexOf("/")+1,Fecha.length))
// Cadena Mes
var Mes= new String(Fecha.substring(Fecha.indexOf("/")+1,Fecha.lastIndexOf("/")))
// Cadena Día
var Dia= new String(Fecha.substring(0,Fecha.indexOf("/")))

// Valido el año
if (isNaN(Ano) || Ano.length<4 || parseFloat(Ano)<1900){
alert('Año inválido')
document.datos.fecha.focus();
return false
}
// Valido el Mes
if (isNaN(Mes) || parseFloat(Mes)<1 || parseFloat(Mes)>12){
alert('Mes inválido')
document.datos.fecha.focus();
return false
}
// Valido el Dia
if (isNaN(Dia) || parseInt(Dia)<1 || parseInt(Dia)>31){
alert('Día inválido')
return false
}
if (Mes==4 || Mes==6 || Mes==9 || Mes==11 || Mes==2) {
if (Mes==2 && Dia > 29 || Dia>30) {
alert('Día inválido')
document.datos.fecha.focus();
return false
}
}

//para que envie los datos, quitar las 2 lineas siguientes
//alert("Fecha correcta.")
return true
}

function mirafecha(){
if (document.datos.fecha.value==""){
//alert("No se ha establecido ninguna fecha");
//document.datos.fecha.focus();
return true;
}else if (!Validar(document.datos.fecha.value)){
document.datos.fecha.focus();
return false;
}else{
return true;
}
}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" link="#FF9966" vlink="#FF9966" alink="#FFCC99">
<br><center><? inicioCuadro("./includes/marco/"); ?><tr>
<td class="Estilo2" align="center" width="540"><div align="center">Edición de noticia </div></td>
</tr><? finCuadro("./includes/marco/"); ?></center>

<form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data" name="datos" id="datos">
<table border=0 align=center cellpadding=1 cellspacing=1>
<TR><TD ALIGN=CENTER VALIGN=MIDDLE>
<?php
$cnx = conectar();
inicioCuadro("./includes/marco/");
if ($val=="nueva")
{
$id=-1;
}
else
{
$id = $val;
$queryTit = "SELECT titulo,texto,foto FROM ".$TABLA." WHERE ".$CAMPO_ID."=".$id;
$query= mysql_query($queryTit) or die(mysql_error());
$numfilas= mysql_num_rows($query);
$alguna=0;
if ($numfilas>0){
list($titulo,$texto,$foto) = mysql_fetch_array($query);
}
}
?>
<input type="hidden" name="pasodatos">
<input type="hidden" name="enviado" value="enviado">
<input type="hidden" name="id" value="<?=$id?>">
<tr>
<td width="540">
<table width="537" >
<tr>
<td width="96" class="Estilo3"><strong>Titulo </strong></td>
<td width="429" class="Estilo3">
<input name="titulo" type="text" class="Estilo3" id="titulo" value='<?=$titulo?>' size="50" maxlength="50"></td>
</tr>
<tr>
<td colspan="2" class="Estilo3"><strong>Texto <br>
<strong>
<textarea name="texto" cols="90" rows="8" class="Estilo3" id="texto"><?=$texto?></textarea>
</strong></strong></td>
</tr>
<?
if ($val=="nueva"){
?>
<tr>
<td class="Estilo3" colspan="2">
<input type="hidden" name="MAX_FILE_SIZE" value="3145728">
<input type="hidden" name="eliminar" value="<?=$foto; ?>">
<input name="foto" type="file" id="foto3" size="37" class="Estilo3"> </td>
</tr>
<?
}else{
?>
<tr>
<td class="Estilo3" colspan="2"><iframe width="520" height="130" src="inc_foto_old.php?id=<?=$id?>&carp_fotos=<?=$C ARP_FOTOS?>&tabla=<?=$TABLA?>&campo_id=<?=$CAMPO_I D?>"></iframe> </td>
</tr>
<? } ?>
</table>
</td>
</tr>
<?php
finCuadro("./includes/marco/");
?>
<tr><td align=right>
<input type="submit" class="Estilo3" value="Guardar">
<input type="button" class="Estilo3" onClick="cancela()" value="Cancelar">
</td></tr>
</TABLE>
<br>
</form>
</body>
<?
//cerramos la conexion con mysql.
mysql_close($cnx);
?>
</html>