Ver Mensaje Individual
  #17 (permalink)  
Antiguo 17/05/2008, 08:01
marcvilap
 
Fecha de Ingreso: mayo-2008
Ubicación: Barcelona
Mensajes: 249
Antigüedad: 16 años
Puntos: 1
Respuesta: duda al subir archivo en el servidor

Pongo todo el codigo de la pagina. Estoy haciendo una pagina web de mascotas.
Donde hay un un buscador en funcion de raza y más cosas. Una vez se hace la busqueda vamos a otra pagina donde hay una tabla que muestra todos los animales que cumplen las especificaciones de la busqueda. Una vez seleccionamos uno de estos animales LLEGAMOS A ESTA PÁGINA, heredando un valor ( ID )




CODIGO

<!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=iso-8859-1" />
<title$>Documento sin t&iacute;tulo</title>

<style type="text/css">
<!--
body,td,th {
color: #000000;
}
body {
background-color: #FFFFFF;
}
.estilo2 {
font-family: Arial, Helvetica, sans-serif;
font-size: 11px;
color: #333333;
}
.estilo {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
color: #999999;
text-align:center;

}
-->
</style>
<link rel="STYLESHEET" type="text/css" href="estilo2.css">
<style type="text/css">
<!--
.Estilo4 {
color: #FF0000;
font-weight: bold;
}
.Estilo5 {
color: #0000FF;
font-weight: bold;
}
.Estilo6 {color: #FF0000}
-->
</style>
</head>

<body>

<div id= "contenedor">

<div id="cabecera"><img src="imagenes/cabezera.jpg" width="380" height="192" alt="clickjob" border="0">


</div>

<div id="centro">

<?php // aquí está el 1er script donde recogemos el valor de ID de otra página.

if(isset($_GET['ID']))
{
session_start ();
$id=$_GET['ID']; //ahi recien vas a tomar la variable.

$_SESSION['id'] = $id; // aquí como me decias pasamos la variable en una varible sesion

}

// Conecta con la BBDD adecuada y guarda el identificador de conecion en link.
$link = mysql_connect("localhost", "root","contraseña");
mysql_select_db("mascotas", $link);

esult = mysql_query("SELECT * FROM ofertas WHERE id_oferta=' ".$id." ' ", $link);// aquí utilizamos esta variable para realizar la busqueda. Yo lo utilizo para identificar un perro y me muestre todas sus caracteristicas en esta página.


if ($row = @mysql_fetch_array($result))
{

// abre la tabla
echo "<table width='80%' align='center' border='0' bordercolor='000000' cellspacing='0' bgcolor='ffffff'> \n";
//Mostramos los nombres de las tablas

echo "<tr> \n";
while ($field = mysql_fetch_field($result)){
echo "<td>$field->name</td> \n";
}

echo "</tr> \n";
do {
echo "<tr> \n";

echo "<table width='450'>
<tr><td width='150'><strong>Nombre :</strong></td><td width='300'>".$row['Nombre']."</td></tr>
<tr><td width='150'><strong>Provincia :</strong></td><td width='300'>".$row['provincia']."</td></tr>
<tr><td><strong>Area :</strong></td><td>".$row['area']."</td></tr>
<tr><td><strong>Raza:</strong></td><td>".$row['raza']."</td></tr> </table><br><br>
<table width='600'>
<tr><td><strong>Mote</strong></td><td>".$row['mote']."</td></tr>
<tr><td width='150' valign='top'><strong>Descripción :</strong> </td><td width='450'>".$row['descripcion']."</td></tr>
</table>";


} while ($row = mysql_fetch_array($result));
echo "</table> \n";
}

else {
echo "&iexcl; ";
}
?>


Aquí empieza el segundo script que es donde no tengo la variable id

<?php


if (isset($_POST['submit'])) {
if(is_uploaded_file($_FILES['fichero']['tmp_name'])) { // verifica haya sido cargado el archivo

session_start(); // lo que me comentabas

$id=$_SESSION['id']; // Utilio esto para guardar el archivo con el nombre de la id.

$ruta= "carpeta/$id".$_FILES['fichero']['name'];

if(move_uploaded_file($_FILES['fichero']['tmp_name'], $ruta)) {

echo "<b>Update realizado correctamente. Datos:</b><br>";

echo "Nombre: <i><a href=\"".$_FILES['fichero']['name']."\">".$_FILES['fichero']['name']."</a></i><br>";
echo "Tipo MIME: <i>".$_FILES['fichero']['type']."</i><br>";
echo "Peso: <i>".$_FILES['fichero']['size']." bytes</i><br>";
echo "<br><hr><br>";
}
}

// A continuación el formulario
}
?>

</tr>
</tr>
</table>
<p align="center">&nbsp;</p>
<p>&nbsp;</p>
</div>
<div id="final">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data">
Curriculum: <input name="fichero" type="file">
<input name="submit" type="submit" value="Upload!">
</form>
</div>
</body>
</html>


Vaya parrafada jaja GRACIAS POR TODO