Foros del Web » Programando para Internet » PHP »

subir imagen de perfil segun usuario

Estas en el tema de subir imagen de perfil segun usuario en el foro de PHP en Foros del Web. buenas que tal? ando por aqui en busca de ayuda. ya que he buscado por el santo google y nada, el problema es el siguiente ...
  #1 (permalink)  
Antiguo 17/05/2012, 17:46
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años
Puntos: 0
subir imagen de perfil segun usuario

buenas que tal?

ando por aqui en busca de ayuda. ya que he buscado por el santo google y nada,

el problema es el siguiente

tengo este script php el cual funciona a la bien. porque eh logrado que suban y se vean las imagenes. pero lo que no eh logrado es que se vea la foto que sube cada usuario. en su perfil ?


el script es este :

esta es la base de datos :

CREATE TABLE IF NOT EXISTS `cambiar_cabezera_usuario` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`imagen` blob,
`id_registro` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_spanish_ci AUTO_INCREMENT=32 ;

y este el :

Código PHP:
<?php require_once('Connections/hoysale.php'); ?>
<?php
if (!isset($_SESSION)) {
  
session_start();
}
$MM_authorizedUsers "";
$MM_donotCheckaccess "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers$strGroups$UserName$UserGroup) { 
  
// For security, start by assuming the visitor is NOT authorized. 
  
$isValid False

  
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  
if (!empty($UserName)) { 
    
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    
$arrUsers Explode(","$strUsers); 
    
$arrGroups Explode(","$strGroups); 
    if (
in_array($UserName$arrUsers)) { 
      
$isValid true
    } 
    
// Or, you may restrict access to only certain users based on their username. 
    
if (in_array($UserGroup$arrGroups)) { 
      
$isValid true
    } 
    if ((
$strUsers == "") && true) { 
      
$isValid true
    } 
  } 
  return 
$isValid
}

$MM_restrictGoTo "Un.php";
if (!((isset(
$_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers$_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  
$MM_qsChar "?";
  
$MM_referrer $_SERVER['PHP_SELF'];
  if (
strpos($MM_restrictGoTo"?")) $MM_qsChar "&";
  if (isset(
$QUERY_STRING) && strlen($QUERY_STRING) > 0
  
$MM_referrer .= "?" $QUERY_STRING;
  
$MM_restrictGoTo $MM_restrictGoTo$MM_qsChar "accesscheck=" urlencode($MM_referrer);
  
header("Location: "$MM_restrictGoTo); 
  exit;
}
?>
<?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_insert"])) && ($_POST["MM_insert"] == "form1")) {
 
  
//Guardar imagen
    
if(is_uploaded_file($_FILES['Imagen']['tmp_name'])) { // verifica haya sido cargado el archivo
    
$ruta"imagenes/".$_FILES['Imagen']['name'];
    
move_uploaded_file($_FILES['Imagen']['tmp_name'], $ruta);
    }

  
$insertSQL sprintf("INSERT INTO cambiar_cabezera_usuario (imagen) VALUES (%s)",
                       
GetSQLValueString($ruta"text"));

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

  
$insertGoTo "deUn.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
<form action="<?php echo $editFormAction?>" method="POST" enctype="multipart/form-data" name="form1">
  <label for="Imagen"></label>
  <input type="file" name="Imagen" id="Imagen">
  <label for="button"></label>
  <input type="submit" name="button" id="button" value="Enviar">
  <input type="hidden" name="MM_insert" value="form1">
</form>
sigue...
  #2 (permalink)  
Antiguo 17/05/2012, 17:47
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años
Puntos: 0
Respuesta: subir imagen de perfil segun usuario

y esta es la otra pagina donde se ve la imagen.:

Código PHP:
Ver original
  1. <?php require_once('Connections/hoysale.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  7.  
  8.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  9.  
  10.   switch ($theType) {
  11.     case "text":
  12.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  13.       break;    
  14.     case "long":
  15.     case "int":
  16.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  17.       break;
  18.     case "double":
  19.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  20.       break;
  21.     case "date":
  22.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  23.       break;
  24.     case "defined":
  25.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  26.       break;
  27.   }
  28.   return $theValue;
  29. }
  30. }
  31.  
  32. $varusuario_un = "-1";
  33. if (isset($_SESSION['MM_Username'])) {
  34.   $varusuario_un = $_SESSION['MM_Username'];
  35. }
  36. mysql_select_db($database_hoysale, $hoysale);
  37. $query_un = sprintf("SELECT * FROM cambiar_cabezera_usuario WHERE cambiar_cabezera_usuario.id_registro AND cambiar_cabezera_usuario.id=%s", GetSQLValueString($varusuario_un, "int"));
  38. $un = mysql_query($query_un, $hoysale) or die(mysql_error());
  39. $row_un = mysql_fetch_assoc($un);
  40. $totalRows_un = mysql_num_rows($un);
  41.  
  42. ?>
  43. <img src="<?php echo $row_un['imagen']; ?>" width="100" height="100">


porfavor ayuda!!!
  #3 (permalink)  
Antiguo 17/05/2012, 19:59
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: subir imagen de perfil segun usuario

Bueno, cuando haces la consulta para agregar la imagen sólo guardas la ruta, sin datos adicionales:

$insertSQL = sprintf("INSERT INTO cambiar_cabezera_usuario (imagen) VALUES (%s)", GetSQLValueString($ruta, "text"));

Y después quieres obtener las imágenes que corresponden al usuario:

$query_un = sprintf("SELECT * FROM cambiar_cabezera_usuario WHERE cambiar_cabezera_usuario.id_registro AND cambiar_cabezera_usuario.id=%s", GetSQLValueString($varusuario_un, "int"));

Lo que se puede simplificar a:

$query_un = sprintf("SELECT * FROM cambiar_cabezera_usuario WHERE id=%s", GetSQLValueString($varusuario_un, "int"));

Lógicamente, primero debes arreglar el INSERT INTO para incluir la id del usuario que sube la imagen.
__________________
- León, Guanajuato
- GV-Foto
  #4 (permalink)  
Antiguo 17/05/2012, 20:20
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años
Puntos: 0
Respuesta: subir imagen de perfil segun usuario

hola muchas gracias!!!

dime como arreglar el INSERT INTO para incluir la id del usuario que sube la imagen?
  #5 (permalink)  
Antiguo 18/05/2012, 00:52
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: subir imagen de perfil segun usuario

O sea qué no hiciste tú todo ese script?

Para insertar sólo necesitas incluir todos los campos y sus respectivos valores en la consulta:
INSERT INTO tabla (campo1, campo2, campoN) VALUES(valor1, valor2, valorN)

Lógicamente, también necesitarás adaptar la consulta para armarla como lo estás haciendo con sprintf().
__________________
- León, Guanajuato
- GV-Foto

Etiquetas: html, imagenes, mysql, perfil, registro, sql, variables, 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 12:16.