Código PHP:
<!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>
<title>Estacion Rap - Sube tus graffitis!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<script type="text/javascript">var clear="images/clear.gif";</script>
<script type="text/javascript" src="unitpngfix.js"></script>
<![endif]-->
</head>
<body>
<?php
$conexion = mysql_connect("sql201.byethost15.com", "user", "pass");
mysql_select_db("database", $conexion);
$queEmp = "SELECT * FROM Discos ORDER BY id DESC";
$resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
$totEmp = mysql_num_rows($resEmp);
if ($totEmp> 0) {
while ($rowEmp = mysql_fetch_assoc($resEmp)) {
}
}
?>
<!-- BEGIN wrapper -->
<div id="wrapper">
<!-- BEGIN header -->
<?
include('arriba.php'); ?>
<!-- END header -->
<!-- BEGIN body -->
<div id="body">
<!-- BEGIN content -->
<div id="content">
<!-- begin post -->
<div class="first post">
<div align="center">
<h3>Sube tus Graffitis!</h3>
<p>
<?
session_start();
if($_POST){
if ($_SESSION['tmptxt'] == $_POST['tmptxt']) {
$key="si";
}
else
{
echo "El codigo anti SPAM esta mal.";
}
}
if($key == "si"){
// Creamos la cadena aletoria
$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$cad = "";
for($i=0;$i<12;$i++) {
$cad .= substr($str,rand(0,62),1);
}
// Fin de la creacion de la cadena aletoria
$tamano = $_FILES [ 'file' ][ 'size' ]; // Leemos el tamaño del fichero
$tamaño_max="50000000000"; // Tamaño maximo permitido
if (if( $tamano < $tamaño_max){ // Comprovamos el tamaño
$destino = 'graff' ; // Carpeta donde se guardata
$sep=explode('image/',$_FILES["file"]["type"]); // Separamos image/
$tipo=$sep[1]; // Optenemos el tipo de imagen que es
if($tipo == "gif" || $tipo == "pjpeg" || $tipo == "bmp" || $tipo == "png" || $tipo == "jpg" || $tipo == "jpeg"){ // Si el tipo de imagen a subir es el mismo de los permitidos, segimos. Puedes agregar mas tipos de imagen
move_uploaded_file ( $_FILES [ 'file' ][ 'tmp_name' ], $destino . '/' .$cad.'.'.$tipo); // Subimos el archivo
include('post.html'); ) {
$que = "INSERT INTO graffos (link, usuario, idusuario) ";
$que.= "VALUES ('".$destino."', '".$_SESSION['nick']."', '".$_SESSION['idusuario']."')";
$res = mysql_query($que, $conexion) or die(mysql_error());
$state = true;
echo "Imagen subida!!";
}
else { echo "Hubo un error al Subir la Imagen";
}
else echo "el tipo de archivo no es de los permitidos";// Si no es el tipo permitido lo desimos
}
else echo "El archivo supera el peso permitido.";// Si supera el tamaño de permitido lo desimos
}
?>
<p>
</p>
</p>
</form>
</div>
</div>
<!-- end post -->
<!-- begin post --><!-- end post -->
<!-- begin post -->
<!-- end post -->
</div>
<!-- END content -->
<!-- BEGIN sidebar -->
<?
include('menu.php'); ?>
<!-- END sidebar -->
<div class="break"></div>
</div>
<!-- END body -->
<!-- BEGIN footer -->
<?
include('abajo.php'); ?>
<!-- END footer -->
</div>
<!-- END -->
</body>
</html>