Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/04/2005, 18:33
derkanzler
 
Fecha de Ingreso: agosto-2003
Ubicación: Venezuela
Mensajes: 82
Antigüedad: 20 años, 7 meses
Puntos: 0
Ayuda Urgente con PHP UPLOAD.

Ayudar Urgente con PHP UPLOAD.

Buenas tardes Estoy utilizando los archivos que coloco Cluster hace tiempo para realizar un upload a las base de datos y me va de pelos.

Mi problema es el siguiente.

Estoy trabajando en un sitio web que consta de las siguientes tablas en una base de datos MySql.
1. Una tabla administrador para guardar información de los administradores del sitio.
2. Una tabla archivos donde estan almacenadas las imágenes. (la tabla del tutorial de CLUSTER.)
3. Una tabla llamada usuarios donde estan los datos de los usuarios que utilizarán los servicios del sitio Web.
4. Una tabla llamada venta_vehiculo donde los usuarios registrados pueden insertar datos de vehiculos que podrán ofertar en la página.

Bien lo que estoy haciendo actualmente es lo siguiente.

Inicialmente inserto los datos de los vehiculos que los usuarios desean vender

Código PHP:
<?php require_once('../../Connections/taxi.php'); ?>
<?php
//initialize the session
session_start();

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_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO venta_vehiculo (titulo_venta, vendedor, Id_vendedor, detalles, foto, modelo, estatus) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['titulo_venta'], "text"),
                       
GetSQLValueString($_POST['vendedor'], "text"),
                       
GetSQLValueString($_POST['Id_vendedor'], "text"),
                       
GetSQLValueString($_POST['detalles'], "text"),
                       
GetSQLValueString($_POST['foto'], "text"),
                       
GetSQLValueString($_POST['modelo'], "text"),
                       
GetSQLValueString($_POST['estatus'], "text"));

  
mysql_select_db($database_taxi$taxi);
  
$Result1 mysql_query($insertSQL$taxi) or die(mysql_error());

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

$colname_taxi "1";
if (isset(
$_GET['Id'])) {
  
$colname_taxi = (get_magic_quotes_gpc()) ? $_GET['Id'] : addslashes($_GET['Id']);
}
mysql_select_db($database_taxi$taxi);
$query_taxi sprintf("SELECT * FROM usuarios WHERE Id = %s"$colname_taxi);
$taxi mysql_query($query_taxi$taxi) or die(mysql_error());
$row_taxi mysql_fetch_assoc($taxi);
$totalRows_taxi mysql_num_rows($taxi);
?>
Luego después de insertar caigo en una página donde la persona puede ver los datos insertados y agregar una imagen para el vehiculo si asi lo desea. (los datos del vehiculo estan insertados en una tabla y la imagen en otra)

Codigo Página verificar datos. (inserta_data_vehicle_ok.php)

Código PHP:
<?php require_once('../../Connections/taxi.php'); ?>
<?php
mysql_select_db
($database_taxi$taxi);
$query_taxi "SELECT * FROM venta_vehiculo ORDER BY id DESC";
$taxi mysql_query($query_taxi$taxi) or die(mysql_error());
$row_taxi mysql_fetch_assoc($taxi);
$totalRows_taxi mysql_num_rows($taxi);
?>
Aca empiezo a utilizar las páginas del Tutorial de Cluster

Pagina que recoge la imagen para insertar imagen al vehiculo. (formulario.php)

Código PHP:
<?php require_once('../Connections/taxi.php'); ?>
<?php
//initialize the session
session_start();

$colname_taxi "1";
if (isset(
$_SESSION['milogin'])) {
  
$colname_taxi = (get_magic_quotes_gpc()) ? $_SESSION['milogin'] : addslashes($_SESSION['milogin']);
}
mysql_select_db($database_taxi$taxi);
$query_taxi sprintf("SELECT * FROM usuarios WHERE usuario = '%s'"$colname_taxi);
$taxi mysql_query($query_taxi$taxi) or die(mysql_error());
$row_taxi mysql_fetch_assoc($taxi);
$totalRows_taxi mysql_num_rows($taxi);
?>
<HTML> 
<HEAD> 
<TITLE>Binario a BD</TITLE> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.Estilo1 {color: #FF0000}
-->
</style>
</HEAD>
<BODY>
<FORM enctype="multipart/form-data" method="post" action="insertar.php">
  <br>
  <br>
  <br>
  <br>
  <br>
  <br>
  <table width="400"  border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>
        <?php 
if (isset($_GET['proceso'])){ 
echo 
$_GET['proceso']."<br>"

?>      </td>
      <td><span class="Estilo1"><?php echo $row_taxi['usuario']; ?></span></td>
    </tr>
    <tr>
      <td class="formularios1"><div align="right">Archivo:
            
    </div></td>
      <td width="279" class="formularios1"><input name="archivo" type="file" class="formularios" size="30"></td>
    </tr>
    <tr>
      <td colspan="2" class="formularios1"><div align="center">
        <INPUT name="submit" type="submit" class="formularios" value="Subir archivo">
      </div></td>
    </tr>
  </table>
</FORM>
</BODY> 
</HTML>
<?php
mysql_free_result
($taxi);
?>
Seguidamente el codigo de la pagina que inserta la informacion en la tabla archivos.
Codigo de la página Insertar.php
Código PHP:
<?php require_once('../Connections/taxi.php'); ?>
<?php
//Primero, arranca el bloque PHP y checkea si el archivo tiene nombre.  Si no fue asi, te remite de nuevo al formulario de inserción: 
// No se comprueba aqui si se ha subido correctamente. 
if (empty($_FILES['archivo']['name'])){ 
header("location: formulario.php?proceso=falta_indicar_fichero"); //o como se llame el formulario .. 
exit; 


//establece una conexión con la base de datos. 
$conexion mysql_connect("localhost","root","") or die("No se pudo realizar la conexion con el servidor."); 
mysql_select_db($database_taxi,$taxi) or die("No se puede seleccionar BD"); // tu_bd es el nombre de la Base de datos .. por siaca. 

// archivo temporal (ruta y nombre). 
$binario_nombre_temporal=$_FILES['archivo']['tmp_name'] ; 

// leer del archvio temporal .. el binario subido. 
// "rb" para Windows .. Linux parece q con "r" sobra ... 
$binario_contenido addslashes(fread(fopen($binario_nombre_temporal"rb"), filesize($binario_nombre_temporal))); 

// Obtener del array FILES (superglobal) los datos del binario .. nombre, tabamo y tipo. 
$binario_nombre=$_FILES['archivo']['name']; 
$binario_peso=$_FILES['archivo']['size']; 
$binario_tipo=$_FILES['archivo']['type']; 
 
//insertamos los datos en la BD. 
$consulta_insertar "INSERT INTO archivos (id, archivo_binario, archivo_nombre, archivo_peso, archivo_tipo) VALUES ('', '$binario_contenido', '$binario_nombre', '$binario_peso', '$binario_tipo')"
mysql_query($consulta_insertar,$taxi) or die("No se pudo insertar los datos en la base de datos."); 
header("location: listar_imagenes.php");  // si ha ido todo bien 
exit; 
?> 
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
</body>
</html>
<?php
mysql_free_result
($taxi);
?>
Ok ahora bien que es lo que realmente quiero hacer?

1. Necesito pirmordialmente recuperar el ID del usuario que está insertando los datos del vehiculo, datos que estan almacenado en la tabla llamada venta_vehiculo
2. Una vez recuperado este ID de “vendedor”, necesito insertarlo de alguna forma en la tabla archivos de la base de datos, puede ser en un campo llamado Id_vendedor, no importa.

Agradezco cualquier ayuda tengo casi 2 semanas pega´o con esto no tengo mucho conocimiento de código PHP y logicamente no domino mucho esto y necesito entregar el sitio pronto.
__________________
Stand Tall and Shake the Heavens!!
http://www.sprache-language-venezuela.c-f-h.net