Foros del Web » Programando para Internet » PHP »

S.O.S. - Admin no sube imagenes

Estas en el tema de S.O.S. - Admin no sube imagenes en el foro de PHP en Foros del Web. Saludos, estoy diseñando un admin y al momento de decirle que me actualice las imágenes este me las borra de la base de datos, solo ...
  #1 (permalink)  
Antiguo 20/11/2011, 13:39
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
S.O.S. - Admin no sube imagenes

Saludos,
estoy diseñando un admin y al momento de decirle que me actualice las imágenes este me las borra de la base de datos, solo me almacena la imagen dentro del ftp y en la bd la elimina..
Les muestro a ver si ven el error

Código PHP:
<?php //require_once('includes/sesion.php'); ?>
<?php 
require_once('../Connections/azimut.php'); ?>
<?php
include_once("fckeditor/fckeditor.php") ;
?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form2")) {

if (
$_POST['opcion']==1){
$ediciondir'../wlc/';  
$uploaddir=$ediciondir;
if (!
is_dir($ediciondir)) {     mkdir($uploaddir0777);    }
move_uploaded_file($_FILES['img2']['tmp_name'], $uploaddir $_FILES['img2']['name']);    
$filename $_FILES['img2']['name'];}
else {
$filename $_POST['img'];
}
  
$updateSQL sprintf("UPDATE inicio SET wlc=%s, tenemos=%s, img=%s WHERE id=%s",
                       
GetSQLValueString($_POST['wlc'], "text"),
                       
GetSQLValueString($_POST['tenemos'], "text"),
                       
GetSQLValueString($_POST['img'], "text"),
                       
GetSQLValueString($_POST['id'], "int"));

 
mysql_select_db($database_azimut$azimut);
 
$Result1 mysql_query($updateSQL$azimut) or die(mysql_error());

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

$colname_Recordset1 "1";
if (isset(
$_GET['id'])) {
  
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_azimut$azimut);
$query_Recordset1 sprintf("SELECT * FROM inicio WHERE id = %s"$colname_Recordset1);
$Recordset1 mysql_query($query_Recordset1$azimut) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
y el formulario
Código PHP:
<form action="<?php echo $editFormAction?>" method="post" name="form2" id="form2" enctype="multipart/form-data">
            <table align="center">
              <tr valign="baseline">
                <td align="right" valign="top" nowrap="nowrap" class="textoINDEX">Texto Bienvenidos:  </td>
                <td class="textoTitulos2"><div align="left"><span class="textoINDEX">
                  <?php
$oFCKeditor 
= new FCKeditor('wlc');
$oFCKeditor->BasePath 'fckeditor/';
$oFCKeditor->Value $row_Recordset1['wlc'];
$oFCKeditor->Create(); 
?>
                  </span></div></td>
              </tr>
              <tr valign="baseline">
                <td align="right" valign="top" nowrap="nowrap" class="textoINDEX">Tenemos para ti:  </td>
                <td class="textoTitulos2"><div align="left"><span class="textoINDEX">
                  <?php
$oFCKeditor 
= new FCKeditor('tenemos');
$oFCKeditor->BasePath 'fckeditor/';
$oFCKeditor->Value $row_Recordset1['tenemos'];
$oFCKeditor->Create(); 
?>
                </span></div></td>
              </tr>
              <tr valign="baseline">
                <td align="right" valign="top" nowrap="nowrap" class="textoINDEX">&nbsp;</td>
                <td class="textoTitulos2">&nbsp;</td>
              </tr>

              <tr valign="baseline" class="textoprincipal">
                <td colspan="2" align="right" nowrap="nowrap"><span class="textoINDEX">Actualizar Imagen?  Si
                    <input name="opcion" type="radio" class="textoprincipal" value="1" />
/No
<input name="opcion" type="radio" class="textoprincipal" value="0" checked="checked" />
                <input name="imagen" type="hidden" class="todopanel" value="<?php echo $row_Recordset1['img']; ?>" size="32" />                
                <input name="img2" type="file" class="textoINDEX" id="img2" />
                </span></span></td>
                </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" class="textoprincipal">&nbsp;</td>
                <td><div align="left"></div></td>
              </tr>
              <tr valign="baseline">
                <td align="right" nowrap="nowrap" class="textoprincipal">&nbsp;</td>
                <td><input type="submit" class="textoINDEX" value="Actualizar" /></td>
              </tr>
            </table>
          <input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>" />
            <input type="hidden" name="MM_update" value="form2" />
            <input type="hidden" name="id" value="<?php echo $row_Recordset1['id']; ?>" />
          </form>
le he dado vueltas y aun persiste el problema.. alguien me ayuda por favor?

Gracias de antemano!!!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 20/11/2011, 14:01
Avatar de s00rk  
Fecha de Ingreso: octubre-2010
Ubicación: Mexico
Mensajes: 238
Antigüedad: 13 años, 5 meses
Puntos: 48
Respuesta: S.O.S. - Admin no sube imagenes

Error esta en la consulta pones

$_POST['img'] donde en el formulario nunca tienes un cmpo con ese nombre solo el img2

a mi parecer en ves de poner eso deverias poner $filename y donde pones $filename = $_POST['img'];

Ahi deveria ser img quedando algo asi:

Código PHP:
Ver original
  1. f ($_POST['opcion']==1){
  2. $ediciondir= '../wlc/';  
  3. $uploaddir=$ediciondir;
  4. if (!is_dir($ediciondir)) {     mkdir($uploaddir, 0777);    }
  5. move_uploaded_file($_FILES['img2']['tmp_name'], $uploaddir . $_FILES['img2']['name']);    
  6. $filename = $_FILES['img2']['name'];}
  7. else {
  8. $filename = "img";
  9. }
  10.   $updateSQL = sprintf("UPDATE inicio SET wlc=%s, tenemos=%s, img=%s WHERE id=%s",
  11.                        GetSQLValueString($_POST['wlc'], "text"),
  12.                        GetSQLValueString($_POST['tenemos'], "text"),
  13.                        GetSQLValueString($filename, "text"),
  14.                        GetSQLValueString($_POST['id'], "int"));

Esto lo que hara filename tendra el nombre de la nueva imagen si seeligio la opcion 1, sino obtendra el nombre de img y en la consulta quedaria img=img por lo que no cambiara el nombre de la imagen actual que este ahi.
  #3 (permalink)  
Antiguo 20/11/2011, 14:15
 
Fecha de Ingreso: octubre-2008
Ubicación: Mar del Plata
Mensajes: 50
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: S.O.S. - Admin no sube imagenes

hola T4ke0veR, la variable $_POST['img'] esta vacia, ademas revisa esta sentencia,
Código PHP:
Ver original
  1. if (!is_dir($ediciondir)) {     mkdir($uploaddir, 0777);    }
  2. move_uploaded_file($_FILES['img2']['tmp_name'], $uploaddir . $_FILES['img2']['name']);    
  3. $filename = $_FILES['img2']['name'];}
  4. else {
  5. $filename = "img";
  6. }

Saludos,

Martin
  #4 (permalink)  
Antiguo 20/11/2011, 14:29
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Respuesta: S.O.S. - Admin no sube imagenes

Aun así sigue enviano vacia... No actualiza la imagen... es como si la variable saliera vacia y no se pq!
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #5 (permalink)  
Antiguo 20/11/2011, 14:39
 
Fecha de Ingreso: octubre-2008
Ubicación: Mar del Plata
Mensajes: 50
Antigüedad: 15 años, 6 meses
Puntos: 1
Respuesta: S.O.S. - Admin no sube imagenes

imprime $filename = $_FILES['img2']['name'] a ver que tiene
  #6 (permalink)  
Antiguo 20/11/2011, 15:01
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Respuesta: S.O.S. - Admin no sube imagenes

igual .. no hace nada imprimiendo eso!

primera vez que esto no me funciona...

puse esto

Código PHP:
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {

if (
$_POST['opcion']==1){
$ediciondir'../wlc/';  
$uploaddir=$ediciondir;
if (!
is_dir($ediciondir)) {     mkdir($uploaddir0777);    }
move_uploaded_file($_FILES['img2']['tmp_name'], $uploaddir $_FILES['img2']['name']);    
$filename $_FILES['img2']['name'];}
else {
$filename $_POST['img'];
}
  
$updateSQL sprintf("UPDATE inicio SET wlc=%s, tenemos=%s, img=%s WHERE id=%s",
                       
GetSQLValueString($_POST['wlc'], "text"),
                       
GetSQLValueString($_POST['tenemos'], "text"),
                       
GetSQLValueString($_POST['img'], "text"),
                       
GetSQLValueString($_POST['id'], "int"));

 
mysql_select_db($database_azimut$azimut);
 
$Result1 mysql_query($updateSQL$azimut) or die(mysql_error());

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

$colname_Recordset1 "1";
if (isset(
$_GET['id'])) {
  
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $_GET['id'] : addslashes($_GET['id']);
}
mysql_select_db($database_azimut$azimut);
$query_Recordset1 sprintf("SELECT * FROM inicio WHERE id = 1"$colname_Recordset1);
$Recordset1 mysql_query($query_Recordset1$azimut) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?> 
Le pase el id = 1 ya q es el q me interesa actualizar
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...

Última edición por T4ke0veR; 20/11/2011 a las 15:35
  #7 (permalink)  
Antiguo 20/11/2011, 16:12
Avatar de NUCKLEAR
Moderador radioactivo
 
Fecha de Ingreso: octubre-2005
Ubicación: Cordoba-Argentina
Mensajes: 5.688
Antigüedad: 18 años, 5 meses
Puntos: 890
Respuesta: S.O.S. - Admin no sube imagenes

A mi me duele la cabeza cuando leo estos códigos, pero lo que note es que a tu sprintf y le pasas como referencia un string a un id que en teoría debe ser numérico entero.

http://php.net/manual/en/function.sprintf.php

s - the argument is treated as and presented as a string.
d - the argument is treated as an integer, and presented as a (signed) decimal number.

Quizas sea ese la causa del fallo.

Saludos
__________________
Drupal Argentina
  #8 (permalink)  
Antiguo 20/11/2011, 16:29
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Respuesta: S.O.S. - Admin no sube imagenes

exacto pero siempre lo he trabajado así y en esta oportunidad no quiere funcionar.. donde dices tu q sea el fallo??? el paso de string???
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...

Etiquetas: admin, formulario, html, imagenes, mysql, sql, sube
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:02.