Ver Mensaje Individual
  #13 (permalink)  
Antiguo 19/06/2008, 16:33
Avatar de jaronu
jaronu
 
Fecha de Ingreso: febrero-2008
Mensajes: 2.183
Antigüedad: 16 años, 2 meses
Puntos: 52
Respuesta: codigo para enviar archibo a remoto y a base de datos ????

Intentalo a si, fijate en las cosas que cambie o agregue de tu code, estan comentadas.



<?php
session_start ();//abrimos una sesion

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']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO fotos (nombre, usuario, lugarfoto, descripcion, foto) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['usuario'], "text"),
GetSQLValueString($_POST['lugarfoto'], "text"),
GetSQLValueString($_POST['descripcion'], "text"),
GetSQLValueString($_POST['foto'], "text"));

mysql_select_db($database_misitio, $misitio);
$Result1 = mysql_query($insertSQL, $misitio) or die(mysql_error());

$id_ultimo = mysql_insert_id(); //recogemos la id del ultimo insert, el de arriba
$_SESSION['id'] = $id_ultimo; // guardamos la variable id en una variable de sesion

$insertGoTo = "enviar-fotos-paso2_personal_restringido.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
--------------------------------------------------etc------

<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Nombre:</td>
<td><input type="text" name="nombre" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Usuario:</td>
<td><input type="text" name="usuario" value="<?php echo $_SESSION['MM_Username']; ?>" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Lugarfoto:</td>
<td><input type="text" name="lugarfoto" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Descripcion:</td>
<td><input type="text" name="descripcion" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insertar registro"></td>
</tr>
</table>
<input type="hidden" name="foto" value="">
<input type="hidden" name="MM_insert" value="form1">
</form>

este es la carga del archibo:


<form action="subir_archivo_personal-restringido.php" method="POST" enctype="multipart/form-data" name="form1">
<p align="center">
<input name="archivo" type="file" id="archivo" onMouseOver="MM_showHideLayers('Layer11','','show' );MM_showHideLayers('Layer11','','show')" value="" size="32" />
<input type="submit" name="Submit" value="Enviar" />
</p>
<div class="Estilo83" id="Layer11" onfocus="MM_showHideLayers('Layer11','','show')">< span class="Estilo85">Los nombres de los archivos deben constar de letras y numero tansolo.</span> <span class="Estilo73 Estilo84">El archibo o foto que vas a enviar no puede tener caracteres especiales ( no reconoce los signos &quot;()!?&iquest;_-&amp;%$ entre otros, ) </span></div>
<p align="center">&nbsp;</p>
<p align="center">&nbsp;</p>
<p align="center">
<label>nombre
<input type="text" name="textfield" />
</label>
</p>
<p align="center" class="Estilo79">LAS FOTOS NO PUEDEN SER DE MAS DE 1 MEGA DE PESO Y DIMENSIONES DE 1000*800 maximo </p>
<p align="center" class="Estilo79"> (si quereis enviar fotos con mas capacidad, enviarmela por e-mail, yo me ocupare de colocarla en la web)</p>
<p align="center">&nbsp; </p>
<p align="center">
<input name="radiobutton" type="radio" value="radiobutton" checked>
Enviando la foto nos das permiso para que podamos publicar la imagen<em><strong> en nuestra web</strong></em>. </p>
<p align="center">
<label></label>
<label></label>
&nbsp;</p>
</form>

este es el codigo de subir archibo:

<?php
// Configurar las dos lineas siguientes
mysql_connect("localhost","root","");
mysql_select_db("mibase");
$nombre = time() . strtr($_FILES['archivo']['name'], "ñ'ÁÉÍÓÚÀÈÌÒÙáéíóúäëïöüàèìòù123456789012345678 90", "n-AEIOUAEIOUaeiouaeiouaeiou");


?>

Se ha subido la imagen a la base de datos


<?php
session_start();//abrimos sesion

$directorio_archivo = "./subir-fotos-personal/"; // tipo /home/user/public_html/archivos/
$nombre = time() . strtr($_FILES['archivo']['name'], "ñ'ÁÉÍÓÚÀÈÌÒÙáéíóúäëïöüàèìòù123456789012345678 90", "n-AEIOUAEIOUaeiouaeiouaeiou");
$tamanio = $_FILES['archivo']['size'];
$tipo = $_FILES['archivo']['type'];
if(!is_file($directorio_archivo.$nombre)) {
copy($_FILES['archivo']['tmp_name'], $directorio_archivo.$nombre);

//hacemos el update a la BBDD
//recuperamos la variable de sesion
$id = $_SESSION['id'];
$res = mysql_query("UPDATE fotos SET foto = '$nombre' WHERE fotosid = '$id')");
$Res = mysql_query($res, $misitio) or die(mysql_error());


echo "Click en el siguiente enlace para finalizar el envio de tu foto <br>";
}
else echo "Este nombre de archibo ya existe.Ya existe una foto con ese nombre.Cambia el nombre del archibo para poder enviar la foto.Gracias.";
?>


La composicion de la Base de Datos es:

Nombre Base de datos: mibase
Tabla: fotos
Campos: fotosid(integro, autoincrement, not nul)
nombre(vanchar, not nul)
usuario(vanchar, not nul)
lugarfoto(vanchar, not nul)
descripcion(vanchar, noto nul)
foto(vanchar,nul)