Código PHP:
<html>
<title>Formulario para subir las img y algunos datos</title>
<head></head>
<body>
<form name="insertar" action="datos.php?estado=enviado" method="POST" enctype="multipart/form-data">
<table width="778" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><b>TÍTULO:</b></td>
<td><input type="text" name="titulo" size="60"></td>
</tr>
<tr>
<td><b>COPETE:</b></td>
<td><input type="text" name="copete" size="60"></td>
</tr>
<tr>
<td><b>NOTA:</b></td>
<td><textarea name="nota" cols="46" rows="10"></textarea></td>
</tr>
<tr>
<td><b>IMAGEN:</b></td>
<td><input type="file" name="img1" size="44"></td>
</tr>
<tr>
<td><b>COPETE IMAGEN:</b></td>
<td><input type="text" name="copete_img1" size="60"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="INGRESAR INFORMACIÓN">
<?
$fecha_de_ingreso = date(Y."-".m."-".d." ".H.":".i.":".s);
?>
<input type="hidden" name="fecha_ingreso" value="<?=$fecha_de_ingreso;?>">
</td>
</tr></table>
</form>
</body>
</html>
Código PHP:
<?
include("config_inc.php");
if($_FILES["img1"]["name"] == ""){
$img1 = "";
$ruta1 = "";
}else{
$img1 = $_FILES["img1"];
$prefijo = time();
$url = "/slpfase1/imgs/2005/";
$directorio = $_SERVER['DOCUMENT_ROOT'].$url;
$ruta = $directorio.$prefijo.$img1["name"];
if (move_uploaded_file($img1['tmp_name'],$ruta)){echo "El archivo ha sido cargado correctamente.<br>/n";
}else{echo "Ocurrió algún error al subir el fichero. No pudo guardarse.<br>/n";
$img['userfile']['error'];}
}
mysql_query("INSERT INTO tutabla (titulo,copete,nota,img1,copete_img1,fecha) VALUES('$titulo','$copete','$nota','$ruta','$copete_img1','$fecha_ingreso')") or die(mysql_error());
?>