Foros del Web » Programando para Internet » PHP »

¿Como actualizo y subo una imagen de una Base de datos con PHP?

Estas en el tema de ¿Como actualizo y subo una imagen de una Base de datos con PHP? en el foro de PHP en Foros del Web. Hola estoy creando un administrador de galerías en PHP y MySQL ocupo poder actualizar el nombre de una imagen guardada en una base de datos ...
  #1 (permalink)  
Antiguo 15/05/2011, 12:44
Avatar de jedidas  
Fecha de Ingreso: septiembre-2009
Mensajes: 10
Antigüedad: 14 años, 7 meses
Puntos: 0
¿Como actualizo y subo una imagen de una Base de datos con PHP?

Hola estoy creando un administrador de galerías en PHP y MySQL ocupo poder actualizar el nombre de una imagen guardada en una base de datos y al mismo tiempo subir una imagen a una carpeta en el servidor.

La parte de agregar un nuevo registro y subir una imagen al mismo tiempo ya esta lista, ahora ocupo poder actualizar un registro y subir una imagen al mismo tiempo estoy usando un codigo pero no funciona para nada podrían ayudarme?

<?php require_once('../Connections/automovil.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']);
}


?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Actualiza imagen</title>
</head>

<body>
<?php
//Destino donde se guardara la foto
$destino = 'ima_microbuses';

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

///Copia la imagen al destino
@move_uploaded_file ( $_FILES [ 'imagen_a' ][ 'tmp_name' ], $destino . '/' . $_FILES['imagen_a']['name']);

//actualizo el registro
$updateSQL = sprintf("UPDATE microbuses SET imagen_a=%s WHERE auto_id=%s",
GetSQLValueString($_FILES['imagen_a'], "text"));

mysql_select_db($database_conexion_usuarios, $conexion_usuarios);
$Result1 = mysql_query($updateSQL, $conexion_usuarios) or die(mysql_error());

$updateGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_actualiza = "-1";
if (isset($_GET['auto_id'])) {
$colname_actualiza = $_GET['auto_id'];
}
mysql_select_db($database_automovil, $automovil);
$query_actualiza = sprintf("SELECT * FROM microbuses WHERE auto_id = %s", GetSQLValueString($colname_actualiza, "int"));
$actualiza = mysql_query($query_actualiza, $automovil) or die(mysql_error());
$row_actualiza = mysql_fetch_assoc($actualiza);
$totalRows_actualiza = mysql_num_rows($actualiza);
?>
<br />
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">Imagen_a:</td>
<td>
<input type="file" name="imagen_a" value="<?php echo htmlentities( $row_actualiza['imagen_a'], ENT_COMPAT, 'utf-8'); ?>" size="32" title="Cargar Fotografia del Automotor" />
<input name="subir" type="submit" id="subir" value="Subir imagen" />
</td>
</table>
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="auto_id" value="<?php echo $row_actualiza['auto_id']; ?>" />
</form>
<table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="center"> <th scope="col"><img src="ima_microbuses/<?php echo $row_actualiza['imagen_a']; ?>" alt="imagen" width="234" height="234" /></th>
</tr><tr align="center"> <th scope="col"> </th>
</tr><tr align="center"><th scope="col"></th></tr>
</table>
</body>
</html>
<?php
mysql_free_result($actualiza);
?>

muchas Gracias por su ayuda

Última edición por jedidas; 15/05/2011 a las 12:55

Etiquetas: Ninguno
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 17:17.