Ver Mensaje Individual
  #9 (permalink)  
Antiguo 05/02/2011, 10:08
Marian_liebe
 
Fecha de Ingreso: febrero-2011
Mensajes: 5
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: renombrar imagenes.

Te paso lo que yo tenia así como esta y como la idea de tunait es buenísima, para este caso, lo que podes hacer es mirando lo que te dejo más abajo fijarte de modificar donde dice $_SESSION['nombre']. por el valor que te devuelve la funcion time()...

El codigo tiene varias casas que no recesitas como un par de referencias al index y muchas otras cosas que hacen a la visualización, no le des bolilla. Si se te complica, avisame y te separo bien lo que tiene que ver con lo que te interesa...

Espero que te sirva!



<?php
//INICIO LA SESION
session_start();

//SI EL USUARIO NO ESTA LOGEADO, LO MANDO AL INDEX
if (empty($_SESSION['nombre']))
{
header('Location:index.php');
}

//DEFINIMOS ALGUNAS VARIABLES NECESARIAS CUANDO SUBIMOS EL ARCHIVO
$status= "";
if ($_POST["action"] == "upload") {
$tamano = $_FILES["archivo"]['size'];
$tipo = $_FILES["archivo"]['type'];
$archivo = $_SESSION['nombre'].".png";

if ($archivo != "") {
$destino = "Usuarios/avatar/".$archivo;
if (copy($_FILES['archivo']['tmp_name'],$destino))
{//ubicación especifica del avatar

$status = "Avatar Cambiado con éxito";

} else {
$status = "Error al subir el archivo";
}
} else {
$status = "Error al subir archivo";
}
}

//OTRAS VARIABLES PARA MOSRTAR EL AVATAR
$nombredelarchivo = "Usuarios/avatar/".$_SESSION['nombre'].".png";
$default = "Usuarios/avatar/default.png";
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Cambiar Avatar</title>
<!-- CSS -->
<link rel="stylesheet" href="agenda.css" type="text/css" media="screen">

</head>
<body class="workPage">
<div id="headerr">
<br>
<br>

<h4>TU AVATAR</h4>
<br>
<br>


<?php if (file_exists($nombredelarchivo)) {?>

<h1><img height= 200 width= 200 src="<?php echo $nombredelarchivo?>" alt="Avatar Actual"></h1>
<br><h5>Cambiar Avatar</h5>

<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" enctype="multipart/form-data">
<input name="archivo" type="file" class="casilla" id="achivo" size="35"><br>
<br><input name="enviar" type="submit" class="boton" id="eviar" value="Subir Avatar!">
<br><input name="action" type="hidden" value="upload">
</form>
<br>

<h5><?php echo $status; ?></h5>

<TABLE width="100%" cellpadding="10">
<TR>
<TD align="center"><a href="index.php">IR AL INDEX</a>
</table>

<?php } else { ?>
<h1><img height= 200 width= 200 src="<?php echo $default?>" alt="Avatar Actual"></h1>
<br>
<h5>Cambiar Avatar</h5>

<form action="<?php echo $_SERVER['REQUEST_URI']?>" method="post" enctype="multipart/form-data">
<input name="archivo" type="file" class="casilla" id="archivo" size="35"><br>
<br><input name="enviar" type="submit" class="boton" id="enviar" value="Subir Avatar!">
<br><input name="action" type="hidden" value="upload">
</form>

<br>
<TABLE width="100%" cellpadding="10">
<TR>
<TD align="center"><a href="index.php">IR AL INDEX</a>
</table>

<h5><?php echo $status?>
<?php } ?></h5>
</div>
</body>
</html>