Foros del Web » Programando para Internet » PHP »

Aporte [subir imagen segun sesion de usuario]

Estas en el tema de Aporte [subir imagen segun sesion de usuario] en el foro de PHP en Foros del Web. Código PHP: <?php  require_once( 'Connections/hoysale.php' );  ?> <?php if (! function_exists ( "GetSQLValueString" )) { function  GetSQLValueString ( $theValue ,  $theType ,  $theDefinedValue  =  "" ,  $theNotDefinedValue  ...
  #1 (permalink)  
Antiguo 24/05/2012, 19:58
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Aporte [subir imagen segun sesion de usuario]

Código PHP:
<?php require_once('Connections/hoysale.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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_update"])) && ($_POST["MM_update"] == "form1")) {
  
//Guardar imagen
    
if(is_uploaded_file($_FILES['Imagen']['tmp_name'])) { // verifica haya sido cargado el archivo
    
$ruta"imagenesdeusuarios/".$_FILES['Imagen']['name'];
    
move_uploaded_file($_FILES['Imagen']['tmp_name'], $ruta);
    } 
  
$updateSQL sprintf("UPDATE registrarse SET imagen=%s WHERE id_user=%s",
                       
GetSQLValueString($ruta"text"),
                       
GetSQLValueString($_POST['id_user'], "int"));

  
mysql_select_db($database_hoysale$hoysale);
  
$Result1 mysql_query($updateSQL$hoysale) or die(mysql_error());

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

$colname_Recordset1 "-1";
if (isset(
$_SESSION['MM_id_user'])) {
  
$colname_Recordset1 $_SESSION['MM_id_user'];
}
mysql_select_db($database_hoysale$hoysale);
$query_Recordset1 sprintf("SELECT * FROM registrarse WHERE id_user = %s"GetSQLValueString($colname_Recordset1"int"));
$Recordset1 mysql_query($query_Recordset1$hoysale) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);

mysql_free_result($Recordset1);
?>
<form action="<?php echo $editFormAction?>" method="post" enctype="multipart/form-data" name="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Imagen:</td>
      <td><input name="Imagen" type="file" id="Imagen" value="<?php echo htmlentities($row_Recordset1['imagen'], ENT_COMPAT''); ?>" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Actualizar registro"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_update" value="form1">
  <input type="hidden" name="id_user" value="<?php echo $row_Recordset1['id_user']; ?>">
</form>
PUNTO 1 = "<?php require_once('Connections/hoysale.php'); ?>" esta es la coneccion a la base de datos tu pones la tuya.

Punto 2 ="($_SESSION['MM_id_user'])) {" tu pones el nombre de tu sesion.

espero se entienda...
saludos
  #2 (permalink)  
Antiguo 24/05/2012, 20:37
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: Aporte [subir imagen segun sesion de usuario]

Pues de entenderse, sí se entiende, el único problema que le veo es que se puede subir cualquier tipo de archivo y comprometes la seguridad del sitio.
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: html, mysql, registro, sql, aportes, usuarios
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 08:47.