PHP form code met bijlage werkt goed maar het bijlage bestand is leeg

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Greg Wing

Greg Wing

28/07/2013 14:05:52
Quote Anchor link
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/************************
* Upload file
*************************/

if (isset($_POST['Submit'])) { //if "email" is filled out, send email
    /*** Upload File ***/

    if($_FILES["file"]["size"] < 20000)
    {

        if ($_FILES["file"]["error"] > 0)
        {

            echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }

        else
        {
        //echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        //echo "Type: " . $_FILES["file"]["type"] . "<br />";
        //echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    
        if (file_exists("upload/" . $_FILES["file"]["name"]))
          {

          //$_FILES["file"]["name"]
          // Do nothing...

          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          $url = "http://asiamodeltalent.com/php/mt/" . "upload/" . $_FILES["file"]["name"];
          }
        }
    }

    else
    {
        echo "Invalid file";
    }

    
/************************
* Insert path and filename to array
*************************/
    

    $fname = $_FILES["file"]["name"];
    $files = array("$fname");


/************************
* Send Message to email
*************************/
    

    $to = "myemail@hotmail.com";
    $from = "webmaster@hotmail.com";
    $subject ="Email met bijlage";
    $message = "Test het email met bijlage.\n";
    $headers = "From: $from";
    
    // boundary
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    
    // headers for attachment
    $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
    
    // multipart boundary
    $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
    $message .= "--{$mime_boundary}\n";

    // preparing attachments
    $pathupload = "http://coder9.com/php/mt/" . "upload/";    
    for($x=0;$x<count($files);$x++){
        //$file = fopen($files[$x],"rb");
            $file = fopen($url[$x], "rb");                
        //$data = fread($file,filesize($files[$x]));
            $data = fread($file, filesize($url[$x]));
        fclose($file);
        $data = chunk_split(base64_encode($data));
        $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" .
        "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" .
        "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
        $message .= "--{$mime_boundary}\n";
    }

    
    // send
    
    $ok = @mail($to, $subject, $message, $headers);
    if ($ok) {
        echo "<p>Email is verstuurd naar $to!</p>";
    }
else {
        echo "<p>Email kan niet verzonden worden!</p>";
    }
    

}

?>
Gewijzigd op 28/07/2013 14:07:33 door Greg Wing
 
Er zijn nog geen reacties op dit bericht.



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.