Este script lo uso para subir las imagenes al host:
evento_imagen.php
Código PHP:
<?php
include ('db-cnx.php');
if(isset($_POST['enviar']) && $_POST['enviar'] == 'Enviar'){
if(!empty($_POST['tituloevento'])){
$tituloevento = $_POST['tituloevento'];
$tituloevento = strtoupper ($tituloevento);
$date = date("d-m-Y-H-i-s");
foreach ($_FILES["foto"]["error"] as $key => $error) {
//Lo de abajo significa si se sube correctamente//
if($error== UPLOAD_ERR_OK){
$nombre_archivo = $_FILES["foto"]["name"][$key];
$tipo_archivo = $_FILES["foto"]["type"][$key];
$tamano_archivo = $_FILES["foto"]["size"][$key];
$temp_archivo = $_FILES["foto"]["tmp_name"][$key];
}
if (!((strpos($tipo_archivo, "gif") || strpos($tipo_archivo, "jpeg")) && ( $tamano_archivo < 1000000)))
{
echo "La extensión o el tamaño de los archivos no es correcta. <br><br><table><tr><td><li>Se permiten archivos .gif o .jpg<br><li>se permiten archivos de 1Mg máximo.</td></tr></table>";
}
else
{
$nom_img = $nombre_archivo;
$directorio = 'imagesr2011/';
if (move_uploaded_file($temp_archivo,$directorio . "/" . $nom_img))
{
// hacemos el INSERT en la BD
$sqlInsertNot = mysql_query("INSERT INTO eventos
(tituloevento, fotos, fecha)
VALUES ('$tituloevento', '$nom_img','$date')",
$db_link) or die(mysql_error());
echo "Las fotos se publicaron correctamente";
}
}
}
}else{
echo "Debe rellenar los campos vacios";
}
}
?>
<html>
<head>
<title></title>
</head>
<H3></H3>
<h5><font color="red">***SOLO ARCHIVOS JPG O GIF, Y QUE SEAN MENORES A 1 Mg***</font></h5>
<form name="evento" action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<body bgcolor="#FFE821">
<p>
Nombre del Evento para las imagenes<br />
<input type="text" name="tituloevento" size="60" />
</p>
<p>
Inserta imagenes<br />
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
<input type="file" name="foto[]" size="50" /> <BR>
</p>
<p>
<input type="submit" name="enviar" value="Enviar" />
</p>
</form>
<a href="imagenesr2011.php">VER IMAGENES</a>
</body>
</html>
imagenesr2011.php
Código PHP:
<?
if(isset($_GET['tituloevento'])){
// asignamos los valores
// a las variables que usaremos
$tituloevento = $_GET['tituloevento'];
}
$sqlevento = mysql_query("SELECT * FROM `eventos` WHERE tituloevento = '$tituloevento' ORDER BY ideventos DESC", $db_link) or die(mysql_error);
if (mysql_num_rows($sqlevento)) {
while($evento = mysql_fetch_array($sqlevento)){
echo'
<html>
<head>galeria imagenes</head>
<body bgcolor="#FFE821">
<div style="position: absolute; left: 80; top: 240">
<center>
<font color="steelblue"><b>FOTOS DE ACTOS,CAMPEONATOS Y EQUIPOS</b></FONT>
</center>
<HR size="5" COLOR="NAVY">
<table>
<caption align="top">'.$evento['tituloevento'].'</caption>
<tr>
<td>
<a href="imagesr2011/'.$evento['foto'].'"><img src="imagesr2011/'.$evento['foto].'"
width="100" height="100"></a>
</td>
</tr>
</table>
<!----------------------------------------------------------->
<HR size="5" COLOR="NAVY">
</div>
</body>
</html>';
}
}
?>