Foros del Web » Programando para Internet » PHP »

Problema subir imagen y mysql

Estas en el tema de Problema subir imagen y mysql en el foro de PHP en Foros del Web. Hola tengo este codigo es de un upload d eimagenes, pero le quise agregar un codigo para que insertara los datos a la base de ...
  #1 (permalink)  
Antiguo 21/01/2011, 14:49
 
Fecha de Ingreso: mayo-2010
Mensajes: 185
Antigüedad: 13 años, 11 meses
Puntos: 2
Problema subir imagen y mysql

Hola tengo este codigo es de un upload d eimagenes, pero le quise agregar un codigo para que insertara los datos a la base de datos, pero no funciona, solo se queda la web en blanco, que le pasa al codigo?

Código PHP:
<!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>
<title>Estacion Rap - Sube tus graffitis!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<script type="text/javascript">var clear="images/clear.gif";</script>
<script type="text/javascript" src="unitpngfix.js"></script>
<![endif]-->
</head>
<body>
<?php
$conexion 
mysql_connect("sql201.byethost15.com""user""pass");
mysql_select_db("database"$conexion);

$queEmp "SELECT * FROM Discos ORDER BY id DESC"
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
$totEmp mysql_num_rows($resEmp);
 if (
$totEmp0) {
    while (
$rowEmp mysql_fetch_assoc($resEmp)) {
 
    }
}
?>
<!-- BEGIN wrapper -->
<div id="wrapper">
  <!-- BEGIN header -->
   <?
include('arriba.php'); ?>
  <!-- END header -->
  <!-- BEGIN body -->
  <div id="body">
    <!-- BEGIN content -->
    <div id="content">
      <!-- begin post -->
      <div class="first post">
        <div align="center">
          <h3>Sube tus Graffitis!</h3>
          <p>
<? 
session_start
();
if(
$_POST){
if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
$key="si";
}
else
{
echo 
"El codigo anti SPAM esta mal.";
}
}
if(
$key == "si"){
// Creamos la cadena aletoria
$str "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$cad "";
for(
$i=0;$i<12;$i++) {
$cad .= substr($str,rand(0,62),1);
}
// Fin de la creacion de la cadena aletoria
$tamano $_FILES 'file' ][ 'size' ]; // Leemos el tamaño del fichero
$tamaño_max="50000000000"// Tamaño maximo permitido

if (if( $tamano $tamaño_max){ // Comprovamos el tamaño 
$destino 'graff' // Carpeta donde se guardata
$sep=explode('image/',$_FILES["file"]["type"]); // Separamos image/
$tipo=$sep[1]; // Optenemos el tipo de imagen que es
if($tipo == "gif" || $tipo == "pjpeg" || $tipo == "bmp" || $tipo == "png" || $tipo == "jpg" || $tipo == "jpeg"){ // Si el tipo de imagen a subir es el mismo de los permitidos, segimos. Puedes agregar mas tipos de imagen
move_uploaded_file $_FILES 'file' ][ 'tmp_name' ], $destino '/' .$cad.'.'.$tipo);  // Subimos el archivo
include('post.html'); ) {
$que "INSERT INTO graffos (link, usuario, idusuario) ";  
    
$que.= "VALUES ('".$destino."', '".$_SESSION['nick']."', '".$_SESSION['idusuario']."')";  
    
$res mysql_query($que$conexion) or die(mysql_error());  
    
$state true;
    echo 
"Imagen subida!!";
}
else { echo 
"Hubo un error al Subir la Imagen";
}
else echo 
"el tipo de archivo no es de los permitidos";// Si no es el tipo permitido lo desimos
}
else echo 
"El archivo supera el peso permitido.";// Si supera el tamaño de permitido lo desimos
}
?> 
    <p>&nbsp;
      </p>
        </p>
    </form>
        </div>
      </div>
      <!-- end post -->
      <!-- begin post --><!-- end post -->
      <!-- begin post -->
      <!-- end post -->
    </div>
    <!-- END content -->
    <!-- BEGIN sidebar -->
     <?
include('menu.php'); ?>
    <!-- END sidebar -->
    <div class="break"></div>
  </div>
  <!-- END body -->
  <!-- BEGIN footer -->
  <?
include('abajo.php'); ?>
  <!-- END footer -->
</div>
<!-- END  -->
</body>
</html>
  #2 (permalink)  
Antiguo 21/01/2011, 15:55
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Problema subir imagen y mysql

Código PHP:
Ver original
  1. <p>
  2. <?  

¿Tienes los errores desactivados cierto? Por eso se queda la pagina en blanco, NO IMPRIMAS ANTES DE USAR session_start();, produce un error porque ya las cabeceras fueron enviadas.

Pon el session_start() antes de TODO el codigo, incluso el codigo HTML.
  #3 (permalink)  
Antiguo 21/01/2011, 16:12
 
Fecha de Ingreso: mayo-2010
Mensajes: 185
Antigüedad: 13 años, 11 meses
Puntos: 2
Respuesta: Problema subir imagen y mysql

Tampoco funciona men, ya puse el session_start() arriba de todo el codigo incluso del html y tampoco funciona
  #4 (permalink)  
Antiguo 21/01/2011, 16:13
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: Problema subir imagen y mysql

¿Te carga la pagina en blanco aun?

Agrega esta linea al principio de tu codigo:
error_reporting(E_ALL);
  #5 (permalink)  
Antiguo 21/01/2011, 16:23
 
Fecha de Ingreso: mayo-2010
Mensajes: 185
Antigüedad: 13 años, 11 meses
Puntos: 2
Respuesta: Problema subir imagen y mysql

MMM no me funciono se queda en blanco aun, antes mejor te doy el codigo separado, para ver si tu puedes arreglarlo, esta es la que sube la imagen, y funciona perfectamente:

Código PHP:
<!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>
<title>Estacion Rap - Sube tus graffitis!</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" />
<!--[if lte IE 6]>
<link rel="stylesheet" type="text/css" href="ie.css" />
<script type="text/javascript">var clear="images/clear.gif";</script>
<script type="text/javascript" src="unitpngfix.js"></script>
<![endif]-->
</head>
<body>
<?php
$conexion 
mysql_connect("sql201.byethost15.com""user""pass");
mysql_select_db("b15_5229524_estacion"$conexion);

$queEmp "SELECT * FROM Discos ORDER BY id DESC"
$resEmp mysql_query($queEmp$conexion) or die(mysql_error());
$totEmp mysql_num_rows($resEmp);
 if (
$totEmp0) {
    while (
$rowEmp mysql_fetch_assoc($resEmp)) {
 
    }
}
?>
<!-- BEGIN wrapper -->
<div id="wrapper">
  <!-- BEGIN header -->
   <?
include('arriba.php'); ?>
  <!-- END header -->
  <!-- BEGIN body -->
  <div id="body">
    <!-- BEGIN content -->
    <div id="content">
      <!-- begin post -->
      <div class="first post">
        <div align="center">
          <h3>Sube tus Graffitis!</h3>
          <p>
<? 
session_start
();
if(
$_POST){
if (
$_SESSION['tmptxt'] == $_POST['tmptxt']) {
$key="si";
}
else
{
echo 
"El codigo anti SPAM esta mal.";
}
}
if(
$key == "si"){
// Creamos la cadena aletoria
$str "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$cad "";
for(
$i=0;$i<12;$i++) {
$cad .= substr($str,rand(0,62),1);
}
// Fin de la creacion de la cadena aletoria
$tamano $_FILES 'file' ][ 'size' ]; // Leemos el tamaño del fichero
$tama&#241;o_max="50000000000"; // Tamaño maximo permitido
if( $tamano $tama&#241;o_max){ // Comprovamos el tamaño 
$destino 'graff' // Carpeta donde se guardata
$sep=explode('image/',$_FILES["file"]["type"]); // Separamos image/
$tipo=$sep[1]; // Optenemos el tipo de imagen que es
if($tipo == "gif" || $tipo == "pjpeg" || $tipo == "bmp" || $tipo == "png" || $tipo == "jpg" || $tipo == "jpeg"){ // Si el tipo de imagen a subir es el mismo de los permitidos, segimos. Puedes agregar mas tipos de imagen
move_uploaded_file $_FILES 'file' ][ 'tmp_name' ], $destino '/' .$cad.'.'.$tipo);  // Subimos el archivo
include('post.html'); 
else { echo 
"el tipo de archivo no es de los permitidos";// Si no es el tipo permitido lo desimos
}
else { echo 
"El archivo supera el peso permitido.";// Si supera el tamaño de permitido lo desimos
}

?> 
    <p>&nbsp;
      </p>
        </p>
    </form>
        </div>
      </div>
      <!-- end post -->
      <!-- begin post --><!-- end post -->
      <!-- begin post -->
      <!-- end post -->
    </div>
    <!-- END content -->
    <!-- BEGIN sidebar -->
     <?
include('menu.php'); ?>
    <!-- END sidebar -->
    <div class="break"></div>
  </div>
  <!-- END body -->
  <!-- BEGIN footer -->
  <?
include('abajo.php'); ?>
  <!-- END footer -->
</div>
<!-- END  -->
</body>
</html>
Este es lo que quiero agregar para que se añadan los datos a la base:

Código PHP:
$que "INSERT INTO graffos (link, usuario, idusuario) ";  
    
$que.= "VALUES ('".$destino."', '".$_SESSION['nick']."', '".$_SESSION['idusuario']."')";  
    
$res mysql_query($que$conexion) or die(mysql_error());  
    
$state true;
    echo 
"Imagen subida!!"

Y este es post.html

Código HTML:
La imagen fue enviada con exito.<br><strong>Datos:</strong><br>
<ul>
  <li>Tipo: <?=$tipo?></li>
  <li>Ubicacion 
    <label>
    <input name="textfield" type="text" id="textfield" value="http://www.estacionrap.byethost15.com/<?=$destino . '/' .$cad.'.'.$tipo?>" />
  </label></li>
</ul>
<br>
<strong>Codigo HTML:</strong><br>
<textarea name="html" id="html"><img src="http://www.estacionrap.byethost15.com/<?=$destino.'/'.$cad.'.'.$tipo?>"><br>Por www.estacionrap.co.cc</textarea><br>
<img src="http://www.estacionrap.byethost15.com/<?=$destino.'/'.$cad.'.'.$tipo?>"> 
  #6 (permalink)  
Antiguo 21/01/2011, 16:48
 
Fecha de Ingreso: mayo-2010
Mensajes: 185
Antigüedad: 13 años, 11 meses
Puntos: 2
Respuesta: Problema subir imagen y mysql

ya lo solucione men gracias! Solo agregue en post lo de para insertar los datos! Gracias

Etiquetas: mysql, subir
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 22:03.