Código PHP:
<form action="<?php echo $editFormAction; ?>" name="fotonuevo" method="POST" enctype="multipart/form-data" id="fotonuevo">
<label for="imagenes">Imagenes:</label>
<input name="imagenes" type="file" multiple id="imagenes">
<input type="submit" name="submit" id="submit" value="Enviar">
<input type="hidden" name="MM_insert" value="fotonuevo">
</form>
Código PHP:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "fotonuevo")) {
$insertSQL = sprintf("INSERT INTO foto (imagenes) VALUES (%s)",
GetSQLValueString($_FILES['imagenes']['name'], "text"));
if (isset($_FILES['imagenes'])){
// Hacemos una condicion en la que solo permitiremos que se suban imagenes y que sean menores a 20 KB
if ((($_FILES["imagenes"]["type"] == "image/gif") ||
($_FILES["imagenes"]["type"] == "image/jpeg") ||
($_FILES["imagenes"]["type"] == "image/png") ||
($_FILES["imagenes"]["type"] == "image/pjpeg")) &&
($_FILES["imagenes"]["size"] < 2000000)) {
//Si es que hubo un error en la subida, mostrarlo, de la variable $_FILES podemos extraer el valor de [error], que almacena un valor booleano (1 o 0).
if ($_FILES["imagenes"]["error"] > 0) {
echo $_FILES["imagenes"]["error"] . "<br />";
} else {
// Si no hubo ningun error, hacemos otra condicion para asegurarnos que el archivo no sea repetido
if (file_exists("../fotografico/foto/" . $_FILES["imagenes"]["name"])) {
echo $_FILES["imagenes"]["name"] . " ya existe. ";
} else {
// Si no es un archivo repetido y no hubo ningun error, procedemos a subir a la carpeta /archivos, seguido de eso mostramos la imagen subida
move_uploaded_file($_FILES["imagenes"]["tmp_name"],
"../fotografico/foto/" . $_FILES["imagenes"]["name"]);
}
}
} else {
// Si el usuario intenta subir algo que no es una imagen o una imagen que pesa mas de 20 KB mostramos este mensaje
}
}
mysql_select_db($database_digitalflash, $digitalflash);
$Result1 = mysql_query($insertSQL, $digitalflash) or die(mysql_error());
$insertGoTo = "foto_index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_digitalflash, $digitalflash);
$query_admin = "SELECT * FROM `admin`";
$admin = mysql_query($query_admin, $digitalflash) or die(mysql_error());
$row_admin = mysql_fetch_assoc($admin);
$totalRows_admin = mysql_num_rows($admin);
mysql_select_db($database_digitalflash, $digitalflash);
$query_fotonuevo = "SELECT * FROM foto";
$fotonuevo = mysql_query($query_fotonuevo, $digitalflash) or die(mysql_error());
$row_fotonuevo = mysql_fetch_assoc($fotonuevo);
$totalRows_fotonuevo = mysql_num_rows($fotonuevo);
?>