Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/07/2009, 15:30
visona
 
Fecha de Ingreso: febrero-2008
Mensajes: 675
Antigüedad: 16 años, 3 meses
Puntos: 5
Renombrar una imagen

Hola;
hace tiempo empece a tratar un tema que quiero retomar http://www.forosdelweb.com/f18/subir...brarla-703085/
Este es el codigo que tengo actualmente
Código PHP:
<?php require_once('Connections/compramos.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']);
}
// $len es la longitud que deseas que tenga el nuevo nombre
function random_name($len) {
    
$chars 'abcdefghijklmnopqrstuvwxyz0123456789';
    
$name '';
    for (
$i 0$i $len; ++$i)
        
$name .= substr($chars, (mt_rand() &#37; strlen($chars)), 1);
    
return $name;
}
 
// Asegurate de agregar la extension correcta
$nuevo_nombre random_name(15) . '.jpg';

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "insertar")) {
  
$insertSQL sprintf("INSERT INTO productos (nombre, categoria, descripcion, imagen, usuario, pdf) VALUES (%s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['Nombre'], "text"),
                       
GetSQLValueString($_POST['categoria'], "int"),
                       
GetSQLValueString($_POST['descripcion'], "text"),
                       
GetSQLValueString("archivos/" $nuevo_nombre"text"),
                       
GetSQLValueString($_POST['usuario'], "text"),
                       
GetSQLValueString($_POST['pdf'], "text"));

  
move_uploaded_file($_FILES['imagen']['tmp_name'], $nuevo_nombre)
  
$Result1 mysql_query($insertSQL$compramos) or die(mysql_error());

  
$insertGoTo "productos.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?>
<!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" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>Documento sin t&iacute;tulo</title>
<!-- TemplateEndEditable -->
<!-- TemplateBeginEditable name="head" -->
<!-- TemplateEndEditable -->
</head>

<body>
<div id="mainContent">
  <form action="<?php echo $editFormAction?>" method="POST" enctype="multipart/form-data" name="insertar" id="insertar">
          <table width="950" border="0">
            <tr>
              <td width="90"><div align="right">Nombre</div></td>
              <td width="8">&nbsp;</td>
              <td width="383"><label>
                <input type="text" name="Nombre" id="Nombre" />
              </label></td>
              <td width="451">&nbsp;</td>
            </tr>
            <tr>
              <td><div align="right">Categoría</div></td>
              <td>&nbsp;</td>
              <td><label>
                <select name="categoria" id="categoria">
                  <?php
do {  
?>
                  <option value="<?php echo $row_categoria['id_categoria']?>"<?php if (!(strcmp($row_categoria['id_categoria'], $row_categoria['id_categoria']))) {echo "selected=\"selected\"";} ?>><?php echo $row_categoria['categoria']?></option>
                  <?php
} while ($row_categoria mysql_fetch_assoc($categoria));
  
$rows mysql_num_rows($categoria);
  if(
$rows 0) {
      
mysql_data_seek($categoria0);
      
$row_categoria mysql_fetch_assoc($categoria);
  }
?>
              </select>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><div align="right">Descripción</div></td>
              <td>&nbsp;</td>
              <td><label>
                <textarea name="descripcion" id="descripcion" cols="45" rows="5"></textarea>
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><div align="right">Imagen</div></td>
              <td>&nbsp;</td>
              <td><label>
                <input type="file" name="imagen" id="imagen" />
              </label></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td align="right">PDF</td>
              <td>&nbsp;</td>
              <td><input type="file" name="pdf" id="pdf" /></td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td><div align="right">
                <input name="usuario" type="hidden" id="usuario" value="<?php echo $row_categoria['id_categoria']; ?>" />
              </div></td>
              <td>&nbsp;</td>
              <td><label>
                <input name="button" type="submit" class="boton" id="button" value="Enviar" />
              </label></td>
              <td>&nbsp;</td>
            </tr>
          </table>
          <input type="hidden" name="MM_insert" value="insertar" />
  </form>
        <h1>&nbsp;</h1>
<!-- end #mainContent --></div>
</body>
</html>
me saca una pagina en blanco, sin errores y sin nada, y la conexion a la base de datos esta bien, ya que si quito el codigo que sube la imagen, muestra el formulario e inserta correctamente.
Un saludo