![]() |
[Pagina principale] [Cerca] [Regolamento e FAQ] [Messaggi privati] |
| 001design.it - Forum > PHP > PHP: inserire un allegato al form | |
| [Grazie forum!] [Registrati] [Profilo] [Lista degli iscritti] [Log-in] [Log-out] |
| [Rispondi] |
| Autore | Messaggio |
|
Romenza Membro Junior Messaggi: 3 |
PHP: inserire un allegato al form Ciao a tutti, credo che il mio problema sia abbastanza semplice: vorrei inserire un allegato al form che ho creato; al momento l'unica cosa che sono riuscita ad ottenere è solo una scritta:"Allegato: C:\PHP\upload\php7B54.tmp". Cosa manca alle mie pagine?
<!-- Commento aggiunto per non interferire con il codice della pagina del forum di 001design.it. codice html <form action="form.php" name="upload" enctype="multipart/form-data" method="post"> <table bgcolor="#333333" align="center" border="0" width="700" cellspacing="1" cellpadding="5"> <tr> <td align="center" bgcolor="#FFFFFF" colspan="11"> <table bgcolor="#333333" align="center" border="0" width="700" cellspacing="1" cellpadding="5"> <tr> <td align="center" bgcolor="#FFFFFF" colspan="11"><h3>MODULO ISCRIZIONE</h3></td> </tr> <tr> <td width="132">NOME:</td> <td width="545" colspan="10" align="center" bgcolor="#FFFFFF"><input name="nome" size=42 value="" /></td> </tr> <tr> <td>COGNOME: </td> <td align="center" bgcolor="#FFFFFF" colspan="10"><input name="cognome" size=42 value="" /></td> </tr> <tr> <td>EMAIL: </td> <td align="center" bgcolor="#FFFFFF" colspan="10"><input name="mail" size=42 value="" /></td> </tr> <tr> <td>Allegato:</td> <td align="center" bgcolor="#FFFFFF" colspan="10"><input type="file" name="allegato" /></td> </tr> <tr> <td align="justify" colspan="11"><div align="center"> <p> <input type="submit" value="INVIA" /> <input type="reset" value="RESET" /> <input type="button" value="INDIETRO" onclick="java-script:history.back()" name="button" /> </p> </div></td> </tr> </table> <h3> </h3></td> </tr> </table> </form> codice php <? ########################### # Configuration # ##################################################### $site_name = "info"; # Put here your Sitename or Company $site_email = "info@mail.com"; # Put here your E-Mail adress #################################################### ##################################################### # This below is the Information which will be sent to the customer ##################################################### if ($nome == "" || $cognome == "" || $mail == "") { echo "<font color=red><B>ERRORE DI TRASMISSIONE</B></font></td></tr></table>"; echo "<BR><font color=black> Errore:</font><BR>Le ricordiamo che i campi NOME, COGNOME, EMAIL, sono obbligatori"; } else { echo "<font color=black><B>LA RINGRAZIAMO PER ESSERSI ISCRITTO AL CORSO $corso. Riceverà una risposta entro 2 giorni lavorativi dall'invio della richiesta.</B></font></td></tr></table>"; PRINT "<CENTER>"; PRINT "<P><BR>Grazie $nome per la Sua iscrizione.<BR>"; PRINT "</CENTER>"; mail("$mail", "Grazie da $site_name!", "Gentile $nome, sarà ricontattato/a entro 2 giorni lavorativi. Se ciò non accadesse per favore mandi una mail a $site_email. ____________________________________________________________ Ecco una copia della Sua Iscrizione: Nome: $nome Cognome: $cognome Email: $mail Allegato: $allegato ____________________________________________________________"); ####################################################### # This below is the information which will # be sent to the Administrator ####################################################### mail("$site_email", "richiesta da $nome", ____________________________________________________________ Nome: $nome Cognome: $cognome Email: $mail Allegato: $allegato ____________________________________________________________"); } ?> Fine commento aggiunto per non interferire con il codice della pagina del forum di 001design.it. --> |
|
|
![]() |
|
Pablito Fondatore Messaggi: 4755 |
Probabilmente questo link ti sarà molto utile: www.w3schools.com/php/php_file_upload.asp |
|
|
![]() |
|
max_400 Moderatore Messaggi: 50 |
form + allegato tutto in una pagina guarda un po se ti piace quest'esempio che potrai modificare a modo tuo in base alle tue esigenzemax400scuola.altervista.org/a_luglio10/php/scarapocchi/form2-1.php <?php if (isset($_POST["submit"])){ $a = $_POST['a']; $da = $_POST['da']; $obj = $_POST['obj']; $testo = $_POST['testo']; $attachment = $_FILES['attachment']['tmp_name']; $attachment_type = $_FILES['attachment']['type']; $attachment_name = $_FILES['attachment']['name']; $intestazioni = "From: " . $da; $messaggio = ""; if (is_uploaded_file($attachment)) { $file = fopen($attachment,'rb'); $data = fread($file, filesize($attachment)); fclose($file); $data = chunk_split(base64_encode($data)); $rand = md5(time()); $boundary = "==Multipart_Boundary_x{$rand}x"; $intestazioni .= "\nMIME-Version: 1.0\n"; $intestazioni .= "Content-Type: multipart/mixed;\n"; $intestazioni .= " boundary=\"{$boundary}\""; $messaggio .= "This is a multi-part message in MIME format.\n\n"; $messaggio .= "--{$boundary}\n"; $messaggio .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $messaggio .= "Content-Transfer-Encoding: 7bit\n\n"; $messaggio .= $testo . "\n\n"; $messaggio .= "--{$boundary}\n"; $messaggio .= "Content-Disposition: attachment;\n"; $messaggio .= " filename=\"{$attachment_name}\"\n"; $messaggio .= "Content-Transfer-Encoding: base64\n\n"; $messaggio .= $data . "\n\n"; $messaggio .= "--{$boundary}--\n"; } else{ $messaggio = $testo; } if (mail($a, $obj, $messaggio, $intestazioni)) { echo "Messaggio inviato con successo."; }else{ echo "Si è verificato un errore nell'invio."; } }else{ ?> <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data"> Destinatario: <input type="text" name="a"><br> Mittente: <input type="text" name="da"><br> Oggetto: <input type="text" name="obj"><br> Messaggio: <textarea name="testo"></textarea><br> Allega file: <input type="file" name="attachment"><br> <input type="submit" name="submit" value="Invia" /> </form><? } ?> |
|
|
|
| Times in GMT +1 (GMT+2 on Summer). Orario italiano. |
| [Rispondi] | |
|
|
|
|
|
Torna al forum di 001design.it - Contatta l’amministratore del forum.
Forum script powered by FunkBoard - Layout and contents copyright © 2004-2010: 001design.it - All rights reserved.