Ver Mensaje Individual
  #3 (permalink)  
Antiguo 16/07/2012, 17:18
ferdinand123
 
Fecha de Ingreso: mayo-2010
Mensajes: 6
Antigüedad: 14 años
Puntos: 0
Respuesta: Subir archivos antes del envio

Ok, primero hay un formulario con su correspondiente envío de adjuntos, el cual funciona perfecto. Luego he agregado el jQuery File Upload para subir archivos al servidor, el cual también funciona. Lo que no sé es como pasarle variables al formulario PHP para que envíe los adjuntos subidos con el jQuery File Upload.

Acá va todo el código en dos partes:

<?php

$direccion_envio= '[email protected]';
//la direccion a la que se enviara el email.

$url= 'http://www.xxxx.php';
//la URL donde esta publicado el formulario. SIN la barra al final

$cantidad_archivos= 5;
//la cantidad máxima de archivos que se permitirá enviar.

//FIN CONFIGURACION

?>

<?PHP
//proceso del formulario
// si existe "enviar"...

$mensaje='<div id="tex1">Solicite su cotización<br />
</div>';

if (isset ($_POST['enviar'])) {

// vamos a hacer uso de la clase phpmailer,
require("inc/class.phpmailer.php");

$mail = new PHPMailer();

//recogemos las variables y configuramos PHPMailer

$mail->FromName = $_POST['nombre'];

$comentario=$_POST['comentario'];

//comprobamos si se adjuntaron archivos, los cargamos en el servidor y los pasamos como adjuntos del email
if (isset($_FILES['files']['tmp_name'])) {
$achivos_adjuntos='';
$i=0;
do {
if($_FILES['files']['tmp_name'][$i] =="")
{
$aleatorio = rand();
$nuevonombre = $aleatorio.'-'.$_FILES['files']['name'][$i];

$achivos_adjuntos .= '<br /><a href="'.$url.'server/php/files/'.$nuevonombre.'">'.$nuevonombre.'</a></strong>';
$mail->AddAttachment($_FILES['files']['files/'][$i], $nuevonombre);
}
$i++;
} while ($i < 1);

}

//comprobamos si todos los campos fueron completados
if ($_POST['nombre']!='' && $_POST['comentario']!='' && $error_archivo=='') {


$nombre=$_POST['nombre'];
$comentario=$_POST['comentario'];

//armamos el html
$contenido = '<html><body>';
$contenido .= '<p>Nombre: <strong>'.$nombre.'</strong></p>';
$contenido .= '<p>Mensaje: <strong>'.$comentario.'</strong></p>';
$contenido .= '<hr />';
$contenido .= '<p>Archivos Adjuntos: '.$achivos_adjuntos.'</p>';
$contenido .= '<hr />';
$contenido .= '</body></html>';
$mail->Body = $contenido;
// si todos los campos fueron completados enviamos el mail

$email = strip_tags(stripslashes($_POST['email']));
//this is repeated for several other fields, then:
$nombre = strip_tags(stripslashes($_POST['nombre']));

if(isInjected($email)) { die(); }
if(isInjected($nombre)) { die(); }

$mail->Send();

$flag='ok';
$mensaje='<div id="tex">Su mensaje se envió con éxito.</div>';

} else {

//si no todos los campos fueron completados se frena el envio y avisamos al usuario
$flag='err';
$mensaje='<div id="error">- xxxx '.$error_archivo.'</div>';

}
}

?>

<!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" xml:lang="es-es" lang="es-es"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Solicitar</title>
<meta name="Keywords" content="zz" />
<meta name="Description" content="zzz" />

<!-- Bootstrap CSS Toolkit styles -->
<link rel="stylesheet" href="http://blueimp.github.com/cdn/css/bootstrap.min.css">
<!-- Generic page styles -->
<link rel="stylesheet" href="css/style.css">
<!-- Bootstrap styles for responsive website layout, supporting different screen sizes -->
<link rel="stylesheet" href="http://blueimp.github.com/cdn/css/bootstrap-responsive.min.css">
<!-- Bootstrap CSS fixes for IE6 -->
<!--[if lt IE 7]><link rel="stylesheet" href="http://blueimp.github.com/cdn/css/bootstrap-ie6.min.css"><![endif]-->
<!-- Bootstrap Image Gallery styles -->
<link rel="stylesheet" href="http://blueimp.github.com/Bootstrap-Image-Gallery/css/bootstrap-image-gallery.min.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet" href="css/jquery.fileupload-ui.css">
<!-- Shim to make HTML5 elements usable in older Internet Explorer versions -->
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->




<script type="text/javascript" src="js2/jquery-1.4.2.min.js"></script>
<script src="js2/jquery.form.js" type="text/javascript" language="javascript"></script>
<script src="js2/jquery.MultiFile.pack.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
OCULTO="none";
VISIBLE="block";
function mostrar1(blo) {
document.getElementById(blo).style.display=VISIBLE ;
document.getElementById('ver_off1').style.display= VISIBLE;
document.getElementById('ver_on1').style.display=O CULTO;
}
function ocultar1(blo) {
document.getElementById(blo).style.display=OCULTO;
document.getElementById('ver_off1').style.display= OCULTO;
document.getElementById('ver_on1').style.display=V ISIBLE;
}
</script>

<style type="text/css">
<!--

-->
</style>


</head>