Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Zip che arriva ma corrotto!

    Salve a tutti, ho uno script per l'invio di un curriculum e di un file zippato che funziona.. a parte il fatto che il file zippato arriva ma non riesco ad aprirlo... mi dice che è corrotto!
    HO provato sia con application/x-zip-compressed che con application/zip... stesso risultato!
    Vi posto lo script se mi volete dare una mano, la parte interessata penso proprio che sia quella degli header..
    Codice PHP:
    <html>
    <head>
    <title>test</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#6D0601" leftmargin="3" topmargin="3" marginwidth="0" marginheight="0" text="#ffffff" link="#ffffff" vlink="#ffffff">
    <?
    function validate_upload($thefile) {
        global 
    $thefile_type$thefile_name$thefile_size;
      
    $my_max_file_size     "307200"# in bytes

        
    $registered_types = array(
                        
    "application/x-zip-compressed" => ".zip",

                        ); 
        
    $allowed_types = array("application/x-zip-compressed");
        
    $start_error "\n";
        if (
    $thefile == "none") { 
            
    $error .= "\n- Nessun documento allegato.
    "
    ;
        } else { 
            if (
    $thefile_size>$my_max_file_size$error .= "\n- Il file allegato supera la dimensione massima consentita.
    "
    ;
            if (!
    in_array($thefile_type$allowed_types)) {
                
    $error .= "\n- Il file che hai inserito non &egrave; del tipo richiesto:
                            
    \n"
    ;
                while (
    $type current($allowed_types)) {
                    
    $error .= "\n" $registered_types[$type] . " (" $type ")
    "
    ;
                    
    next($allowed_types);
                }
                
    $error .= "\n";
            }
            if (
    $error) {
                
    $error $start_error $error "\n";
                return 
    $error;
            } else {
                return 
    false;
            }
        }

    ?> 
    <font face="Arial, Helvetica, sans-serif" size="2">

    <?
    if ($op=="invio") {
        
    $error=0;
        
    $msg="";
        if (
    $nome=="") {
            
    $error=1;
            
    $msg.="- Il campo nome è vuoto.
    "
    ;
        }
        if (
    $cognome=="") {
            
    $error=1;
            
    $msg.="- Il campo cognome è vuoto.
    "
    ;
        }
        if (
    $email=="") {
            
    $error=1;
            
    $msg.="- Il campo email è vuoto.
    "
    ;
        }
        if (
    $email!="" && !eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email)) {
            
    $error=1;
            
    $msg.="- L'email inserita non è valida.
    "
    ;    
        }
        if (
    $commento=="") {
            
    $error=1;
            
    $msg.="- Il campo commento è vuoto.
    "
    ;
        }
        
    $error_file="";
        if (!
    $thefile || $thefile=="none" || $thefile=="") {
            
    $error=1;
            
    $msg.="- Non hai inserito il curriculum.
    "
    ;
        } else 
    $error_file validate_upload($thefile);
        if (
    $error==|| $error_file!="") {
            echo
    "

    Attenzione! Si sono verificati i seguenti errori:
    $msg
    $error_file
    <a href=\"javascript:history.back()\">Clicca qui</a> per reinserire i dati."
    ;    
        } else {
            
    $emailto="info@miosito.com"
            
    $data=date("j/m/Y");
            
    $ora=date("h:i:s");
            
            
    $headers "MIME-Version: 1.0\n";
            
    $headers .= "Content-Type: multipart/mixed; boundary=\"XX-1234DED00099A\"\n";
            
    $headers .= "Content-Transfer-Encoding: 7bit\n";
            
    $headers .= "From: $email\n";
            
            
    $messaggio="--XX-1234DED00099A\n";
            
    $messaggio.="Content-Type: text/plain; charset=iso-8859-1\n";
            
    $messaggio.="Content-Transfer-Encoding: 7bit\n";

            
    $messaggio.="Curriculum inviato il $data alle $ora\n\nDati inseriti\n";
            
    $messaggio.="Nome: $nome\nCognome: $cognome\n";
            if (
    $telefono!=""$messaggio.="Telefono: $telefono\n";
            
    $messaggio.="Email: $email\nCommento:\n$commento\n";
            
    $oggetto_send="Invio Curriculum";
            
            
            
    $messaggio.="--XX-1234DED00099A\n";
            
    $messaggio.="Content-Type: application/x-zip-compressed; name=\"curriculum.zip\"\n";
            
    $messaggio.="Content-Transfer-Encoding: base64\n";
            
    $messaggio.="Content-Description: \"Curriculum\"\n";
            
    $messaggio.="Content-Disposition: attachment\n";
            
            
    $fp=@fopen($thefile"r");
            if (
    $fp) {
                
    $data fread($fpfilesize($thefile));    
            }
            
    $curr base64_encode($data);
            
    $messaggio .= "$curr\n--XX-1234DED00099A--\n";
            if (!
    mail($emailto$oggetto_send$messaggio$headers)) {
                echo
    "
    [b]Attenzione.[/b]
    Si sono verificati degli errori durante l'invio della Email.

                Vi preghiamo di riprovare <a href=\"javascript: history.back()\">cliccando qui.</a>

                Se l'errore persiste Vi invitamo a riprovare più tardi. Grazie."
    ;
            }
            else {
                
    $messaggio_risposta="Grazie per averci contattato.\nIl vostro curriculum è stato inoltrato al responsabile del personale.\n\nDati inseriti\n";
                
    $messaggio_risposta.="Nome: $nome\nCognome: $cognome\n";
                if (
    $telefono!=""$messaggio_risposta.="Telefono: $telefono\n";
                
    $messaggio_risposta.="Commento:\n$commento\n\n";
                
    $messaggio_risposta.="Distinti saluti\n";
                
    $oggetto2="Curriculum inoltrato";
                
    mail($email$oggetto2$messaggio_risposta,"From: Gestione-Curriculum <$emailto>");
                echo 
    "
    [b]Email inviata correttamente.[/b]

                
    I dati inseriti sono i seguenti:

    "
    ;
                echo
    "Nome:[b] $nome [/b]

                Cognome:[b] 
    $cognome[/b]
    "
    ;
                if (
    $telefono!="") echo"Telefono: [b]$telefono[/b]
    "
    ;
                echo
    "Email: [b]$email[/b]
    Commento:[b] "
    .nl2br($commento)."[/b]

                

    Grazie per averci contattato."
    ;
            }
        }
        
    } else {
    ?>
                

    Form per invio curriculum


          <form enctype="multipart/form-data" method="post" action="<?=$PHP_SELF?>" name="contatti">
            <table width="550" border="0" cellspacing="3" cellpadding="0">
              <tr> 
                <td>Nome *</td>
                <td> 
                  <input type="text" name="nome" size="30">
                </td>
              </tr>
              <tr> 
                <td>Cognome *</td>
                <td> 
                  <input type="text" name="cognome" size="30">
                </td>
              </tr>
              <tr> 
                <td>Telefono</td>
                <td> 
                  <input type="text" name="telefono" size="30">
                </td>
              </tr>
              <tr> 
                <td>Email *</td>
                <td> 
                  <input type="text" name="email" size="30">
                </td>
              </tr>
              <tr> 
                <td>Allega il tuo curriculum + 1 foto
    (formato .zip - Max 300 Kb) *</td>
                <td>
                  <input type="hidden" name="MAX_FILE_SIZE" value="307200"> 
                  <input name="thefile" type="file" SIZE="35">
                </td>
              </tr>
              <tr> 
                <td>Commento *</td>
                <td> 
                  <textarea name="commento" wrap="VIRTUAL" cols="30" rows="5"></textarea>
                </td>
              </tr>
              <tr> 
                <td colspan="2">
                  <div align="center">
                      <input type="hidden" name="op" value="invio">
                    <input type="submit" name="Submit" value="Invia">
                    <input type="reset" name="Submit2" value="Reimposta">
                  </div>
                </td>
              </tr>
            </table>
          </form>
          <font size="1">I campi con l'asterisco sono obbligatori.

          <?
    }
    ?> 
           </font>
          
    </table>
    </body>

    </html>
    Vi ringrazio tutti!
    What is the |\/|atrix?

  2. #2
    Utente di HTML.it L'avatar di M4rko
    Registrato dal
    Dec 2000
    Messaggi
    619
    Quando leggi l'allegato
    codice:
    $curr = base64_encode($data);
    dovrebbe diventare
    codice:
    $curr = chunk_split(base64_encode($data));
    Questo serve perche i dati dell'allegato, in base64, devono essere mandati in righe (chunk) non superiori a 76 caratteri, ed è quello che fa la funzione chunk_split
    www.php.net/check_split
    Tutti hanno bisogno di credere in qualcosa.
    Io credo che mi farò un'altra birra.


  3. #3
    Non so come ringraziarti!!! Ha funzionato!
    Ciao!
    What is the |\/|atrix?

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.