Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Form + caricamento img

  1. #1

    Form + caricamento img

    Ciao,
    premetto che sono abbastanza ignorante sulla questione PHP.
    Quello che mi servirebbe capire è come riuscire a far caricare un file che risiede sul computer dell'utente tramite una form ovvero:

    ho dei campi di testo e un campo dove far selezionare il file dall'utente una volta fatto questo cosa devo inserire nel codice PHP per fare in modo che oltre ai dati testuali venga allegato il file.

    il codice che ho ora è il seguente:

    Codice PHP:
    <?php
     
     $headers 
    .= "Content-Type: text/html; charset= iso-8859-1\n\n";

     
    $dachinome=trim(stripslashes($_POST["nome"]));

     
    $dachiemail="<".trim(stripslashes($_POST["mail"])).">"

     
    $headers .= "From: $dachinome $dachiemail\r\n";
     
     
    $to ="info@turbolento.net";
     
     
    $subject ="TURBOLENTO.NET .: Iscrizione PedalatAzzurra :.";
     
     
    $body "
    Dati dell'utente:\n\n

    "
    ;
     
    $body .= "[b]Nome[/b]: " trim(stripslashes($_POST["nome"]))  . "
    \n"
    ;
     
    $body .= "[b]Cognome[/b]: " trim(stripslashes($_POST["cognome"]))  . "
    \n"
    ;
     
    $body .= "[b]Via[/b]: " trim(stripslashes($_POST["via"]))  . "
    \n"
    ;
     
    $body .= "[b]C.A.P.[/b]: " trim(stripslashes($_POST["cap"]))  . "
    \n"
    ;
     
    $body .= "[b]CItt&agrave;[/b]: " trim(stripslashes($_POST["citta"]))  . "
    \n"
    ;
     
    $body .= "[b]Tel.[/b]: " trim(stripslashes($_POST["tel"]))  . "
    \n"
    ;
     
    $body .= "[b]E-mail[/b]: " trim(stripslashes($_POST["mail"]))  . "
    \n"
    ;
     
    $body .= "[b]Data di nascita[/b]: " trim(stripslashes($_POST["data"]))  . "
    \n"
    ;
     
    $body .= "[b]Societ&agrave; sportiva[/b]: " trim(stripslashes($_POST["ass_sport"]))  . "
    \n"
    ;
     
    $body .= "[b]N&deg; tessera[/b]: " trim(stripslashes($_POST["num_tessera"]))  . "
    \n"
    ;
     


     
      if (@
    mail($to$subject$body$headers))
     {
     
         echo 
    "la mail &egrave; stata inviata correttamente";
     
        
    $headers "Content-Type: text/html; charset= iso-8859-1\n\n"

        
    $headers .= "From: \r\n";

        
    mail($_POST["mail"],$subject$body$headers);
     
     }
     
     else
     
     {
     
         echo 
    "Si sono verificati dei problemi nell'invio della mail.
    "
    ;
        echo 
    "[url='pop.html']riprova[/url]";
     
     }
       
    ?>
    La Vita è come un temporale:
    Prenderla nel c**o è un lampo!

  2. #2
    forse ho risolto:

    Codice PHP:
    <?php
     
    if(!isset($_POST)) $_POST $HTTP_POST_VARS;
    if(!isset(
    $_FILES)) $_FILES $HTTP_POST_FILES;

    $attach $_FILES["allegato"]["tmp_name"];
    $file_name $_FILES["allegato"]["name"];
    $file_type $_FILES["allegato"]["type"];
    $file_size $_FILES["allegato"]["size"];

    $boundary md5(uniqid(microtime()));

    $file = @fopen($attach"r");
    $contents = @fread($file$file_size);
    $encoded_attach chunk_split(base64_encode($contents));
    @
    fclose($file);
     
    $headers .= "MIME-version: 1.0\n";
    $headers .= "Content-Type: text/html; charset= iso-8859-1\n\n";
    $headers .= "X-attachments: $file_name\n";

     
    $dachinome=trim(stripslashes($_POST["nome"]));

     
    $dachiemail="<".trim(stripslashes($_POST["mail"])).">"

     
    $headers .= "From: $dachinome $dachiemail\r\n";
     
     
    $to ="gr1@slalom.it";
     
     
    $subject ="Da Kine .: WinShow :.";
     
     
     
    $mail_body "Content-Type: text/plain; charset=us-ascii\n";
     
    $mail_body "Content-Transfer-Encoding: 7bit\n\n";
     
    $body "
    Dati dell'utente:\n\n

    "
    ;
     
    $body .= "[b]Ragione Sociale[/b]: " trim(stripslashes($_POST["rsoc"]))  . "
    \n"
    ;
     
    $body .= "[b]Nome[/b]: " trim(stripslashes($_POST["nome"]))  . "
    \n"
    ;
     
    $body .= "[b]Cognome[/b]: " trim(stripslashes($_POST["cognome"]))  . "
    \n"
    ;
     
    $body .= "[b]Via[/b]: " trim(stripslashes($_POST["via"]))  . "
    \n"
    ;
     
    $body .= "[b]C.A.P.[/b]: " trim(stripslashes($_POST["cap"]))  . "
    \n"
    ;
     
    $body .= "[b]CItt&agrave;[/b]: " trim(stripslashes($_POST["citta"]))  . "
    \n"
    ;
     
    $body .= "[b]Tel.[/b]: " trim(stripslashes($_POST["tel"]))  . "
    \n"
    ;
     
    $body .= "[b]E-mail[/b]: " trim(stripslashes($_POST["mail"]))  . "
    \n"
    ;
     
    $body .= "[b]Nome Agente[/b]: " trim(stripslashes($_POST["agente"]))  . "
    \n"
    ;
     
    $mail_body "Content-type: $file_type; name=\"$file_name\"\n"
     
    $mail_body .= "Content-Transfer-Encoding: base64\n";
     
    $mail_body .= "$encoded_attach\n"
     
     
      if (@
    mail($to$subject$body$headers))
     {
     
         echo 
    "la mail &egrave; stata inviata correttamente";
     
        
    $headers "Content-Type: text/html; charset= iso-8859-1\n\n"

        
    $headers .= "From: Turbolento.net <info@turbolento.net>\r\n";

        
    mail($_POST["mail"],$subject$body$headers);
     
     }
     
     else
     
     {
     
         echo 
    "Si sono verificati dei problemi nell'invio della mail.
    "
    ;
        echo 
    "[url='pop.html']riprova[/url]";
     
     }
     
    ?>
    ma non mi da l'allegato... come mai???
    La Vita è come un temporale:
    Prenderla nel c**o è un lampo!

  3. #3
    Chi l'ha dura la vince!!! alla fine ce l'ho fatto, con il seguente codice:

    Codice PHP:
    <?php

    $to 
    "mail@mail.it";

    $subject "Oggetto";

    // INTESTAZIONI SUPPLEMENTARI
    $headers "From: ";
    $headers .= "Content-Type: text/html; charset=iso-8859-1\n";

    // RENDIAMO LO SCRIPT COMPATIBILE CON LE VERSIONI DI PHP < 4.1.0
    if(!isset($_POST)) $_POST $HTTP_POST_VARS;
    if(!isset(
    $_FILES)) $_FILES $HTTP_POST_FILES;

    // RIPULIAMO I VARI CAMPI DEL MODULO
    $rsoc trim($_POST["rsoc"]);
    $nome trim(stripslashes($_POST["nome"]));
    $cognome trim(stripslashes($_POST["cognome"]));
    $via trim(stripslashes($_POST["via"]));
    $n trim(stripslashes($_POST["n"]));
    $citta trim(stripslashes($_POST["citta"]));
    $prov trim(stripslashes($_POST["prov"]));
    $cap trim(stripslashes($_POST["cap"]));
    $tel trim(stripslashes($_POST["tel"]));
    $mail trim(stripslashes($_POST["mail"]));
    $agente trim(stripslashes($_POST["agente"]));



    // ASSEGNIAMO A VARIABILI PIU' LEGGIBILI, LE PROPRIETA' DELL'ALLEGATO
    $attach $_FILES["allegato"]["tmp_name"];
    $file_name $_FILES["allegato"]["name"];
    $file_type $_FILES["allegato"]["type"];
    $file_size $_FILES["allegato"]["size"];

    // DELIMITATORE
    $boundary md5(uniqid(microtime()));

    // APRIAMO L'ALLEGATO PER LEGGERLO E CODIFICARLO
    $file = @fopen($attach"r");
    $contents = @fread($file$file_size);
    $encoded_attach chunk_split(base64_encode($contents));
    @
    fclose($file);

    // INTESTAZIONI DELLA MAIL
    $mail_headers "From: ";
    $mail_headers .= "MIME-version: 1.0\n";
    $mail_headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"";
    $mail_headers .= "X-attachments: $file_name\n";


    // COSTRUIAMO IL CORPO DELLA MAIL
    $mail_body "--$boundary\n";
    $mail_body .= "Content-Type: text/plain; charset=us-ascii\n";
    $mail_body .= "Content-Transfer-Encoding: 7bit\n\n";
    $mail_body .= "Ragione Sociale: $rsoc\n";
    $mail_body .= "Nome: $nome\n";
    $mail_body .= "Cognome: $cognome\n";
    $mail_body .= "Via: $via $n\n";
    $mail_body .= "Citta: $citta ($prov), $cap\n";
    $mail_body .= "Telefono: $tel\n";
    $mail_body .= "E-Mail: $mail\n";
    $mail_body .= "Nome Agente: $agente\n\n";
    $mail_body .= "--$boundary\n";
    $mail_body .= "Content-type: $file_type; name=\"$file_name\"\n";
    $mail_body .= "Content-Transfer-Encoding: base64\n";
    $mail_body .= "$encoded_attach\n";
    $mail_body .= "--$boundary--\n";


    // INVIO DELLA MAIL
    if(@mail($to$subject$mail_body$mail_headers)) { // SE L'INVIO È ANDATO A BUON FINE...

    echo "La mail è stata inoltrata con successo.";
        
    mail($_POST["mail"],$subject$mail_body$mail_headers);

    } else {
    // ALTRIMENTI...

    echo "Si sono verificati dei problemi nell'invio della mail.";
    echo 
    "[url='form.html']riprova[/url]";

    }

    ?>


    L'unico problema è che l'allegato che ho è un'immagine dello stesso peso dell'originale ma ad una dimensio di 160px per lato... come mai???
    La Vita è come un temporale:
    Prenderla nel c**o è un lampo!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.