Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/10/2011, 05:50
ofertasdiarias
 
Fecha de Ingreso: marzo-2011
Mensajes: 115
Antigüedad: 13 años, 1 mes
Puntos: 0
Respuesta: Problemas para subir archivos con php

hola mira yo tengo este codigo si suben las fotos pero no eh logrado ver las fotos, pero quizas te ayude.

formulario.php

Código PHP:
Ver original
  1. <?php require_once('Connections/anunciosuy.php'); ?>
  2. <?php
  3. $colname_imagen = "-1";
  4. if (isset($_GET['fleImagen'])) {
  5.   $colname_imagen = (get_magic_quotes_gpc()) ? $_GET['fleImagen'] : addslashes($_GET['fleImagen']);
  6. }
  7. mysql_select_db($database_anunciosuy, $anunciosuy);
  8. $query_imagen = sprintf("SELECT Titulo, Imagen FROM formulario WHERE Imagen = '%s'", $colname_imagen);
  9. $imagen = mysql_query($query_imagen, $anunciosuy) or die(mysql_error());
  10. $row_imagen = mysql_fetch_assoc($imagen);
  11. $totalRows_imagen = mysql_num_rows($imagen);
  12.  
  13. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  14. {
  15.   $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
  16.  
  17.   switch ($theType) {
  18.     case "text":
  19.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  20.       break;    
  21.     case "long":
  22.     case "int":
  23.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  24.       break;
  25.     case "double":
  26.       $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  27.       break;
  28.     case "date":
  29.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  30.       break;
  31.     case "defined":
  32.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  33.       break;
  34.   }
  35.   return $theValue;
  36. }
  37.  
  38. $editFormAction = $_SERVER['PHP_SELF'];
  39. if (isset($_SERVER['QUERY_STRING'])) {
  40.   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  41. }
  42.  
  43. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  44.     $tipo_prod = $_POST["Submit"];
  45.  
  46.     //Guardar imagen
  47.     if(is_uploaded_file($_FILES['fleImagen']['tmp_name'])) { // verifica haya sido cargado el archivo
  48.     $ruta= "imagenes/".$_FILES['fleImagen']['name'];
  49.     move_uploaded_file($_FILES['fleImagen']['tmp_name'], $ruta);
  50.     }
  51.   $insertSQL = sprintf("INSERT INTO formulario (Titulo, Imagen) VALUES (%s, %s)",
  52.                        GetSQLValueString($_POST['txttitulo'], "text"),
  53.                        GetSQLValueString($ruta, "text"));
  54.  
  55.   mysql_select_db($database_anunciosuy, $anunciosuy);
  56.   $Result1 = mysql_query($insertSQL, $anunciosuy) or die(mysql_error());
  57.   $insertGoTo = "subiendo.php";
  58.   if (isset($_SERVER['QUERY_STRING'])) {
  59.     $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  60.     $insertGoTo .= $_SERVER['QUERY_STRING'];
  61.   }
  62.   header(sprintf("Location: %s", $insertGoTo));
  63. }
  64. ?><style type="text/css">
  65. <!--
  66. #Layer1 {
  67.     position:absolute;
  68.     left:84px;
  69.     top:61px;
  70.     width:61px;
  71.     height:81px;
  72.     z-index:1;
  73. }
  74. -->
  75. </style>
  76. <div id="Layer1">
  77.   <form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="form1" id="form1">
  78.     <label for="textfield">Titulo :</label>
  79.     <input type="text" name="txttitulo" id="txttitulo" />
  80.     <label for="file">Imagen :</label>
  81.     <input type="file" name="fleImagen" id="fleImagen" />
  82.     <label for="Submit"></label>
  83.     <input type="submit" name="Submit" value="Enviar" id="Submit" />
  84. <input type="hidden" name="MM_insert" value="form1">
  85.   </form>
  86. </div>
  87. <p>
  88.   <?php
  89. ?>
  90. </p>
  91. <p><img name="" src="<?php echo $row_imagen['Imagen']; ?>" alt="" /> </p>

ingreso_exitoso.php

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5. </head>
  6.  
  7. ingreso existoso
  8. </body>
  9. </html>

subiendo.php

Código PHP:
Ver original
  1. <ul>
  2. <img src="/imagenes/<?php echo $row_imagen['imagen']; ?>"/>
  3. <ul/>
  4. <?php require_once('Connections/anunciosuy.php'); ?>
  5. <?php
  6. mysql_select_db($database_anunciosuy, $anunciosuy);
  7. $query_imagen = "SELECT Imagen FROM formulario ORDER BY Imagen ASC";
  8. $imagen = mysql_query($query_imagen, $anunciosuy) or die(mysql_error());
  9. $row_imagen = mysql_fetch_assoc($imagen);
  10. $totalRows_imagen = mysql_num_rows($imagen);
  11.  
  12. ?>

es a modo de referencia tu le pones los datos que quieras, pero asi sube a la carpeta y se guarda en la base de datos, lo unico que yo aun no eh logrado poder verla..