copy Attachement from Email on server (files copied are not valid)

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default copy Attachement from Email on server (files copied are not valid)

    Hi,
    I'm getting emails from an address trough a script and I want to copy the
    attached files on the server. I can get the files and copy them on the
    server (trough the function below) BUT the files are not valid (images
    cannot be displayed)

    how can I solve this?

    ------------------------------------------
    function get_attachments($mbox,$msgno){

    $o = imap_fetchstructure($mbox, $msgno);
    $dir = "C:/AppServ/www/getinfo/fileadmin/testmail/"; // TEST

    if ($o->type == 1 || ($o->ifsubtype == 1 && $o->subtype == 'MIXED')) {

    $parts = $o->parts;
    $i=1;
    $retour = array();
    foreach($parts as $part) {
    $fname = '';

    if (!isset($part->encoding) && $part->encoding == 3) {
    $str = imap_base64(trim(@imap_fetchbody($mbox, $msgno,$i)));
    } else {
    $str = imap_fetchbody($mbox, $msgno,$i);
    }
    if ($part->ifdparameters == 1) {
    $dparams = $part->dparameters;
    foreach($dparams as $dparam) {
    if ($dparam->attribute == "FILENAME") {
    $fname = $dparam->value;
    }
    }
    }
    if ($fname=="") {
    if ($part->ifparameters == 1) {
    $params = $part->parameters;
    foreach($params as $param) {
    if ($param->attribute == "NAME") {
    $fname = $param->value;
    }
    }
    }
    }
    if ($fname=="") {$fname = "part$i";}

    $fp = fopen($dir.$fname,"wb");
    if (!$fp) { return FALSE; }
    fwrite($fp,$str);
    fclose($fp);
    $i++;
    }
    return $retour;
    } else {
    return "no attach";
    }
    }


    nic den Guest

  2. Similar Questions and Discussions

    1. i m using asp to copy a file but its not copied
      hi i m using scripting.filesystemobject to copy a file from server directory with another name, but i m not able to do it whenever i call that...
    2. Offering music files that cannot be copied
      Hi, I want to make available a few music tracks on the website I am building but I don?t want the user to be able to copy the files. What is the...
    3. CDOSYS - IF NOT A VALID EMAIL
      with the cdosys script i have, it works fine if you have a dim email that is an email address, but if a user were to leave that field blank, or not...
    4. No files copied using Copy Project
      Christopher, Double check that you are doing everything as outlined in the following kb article...
    5. compiled DLL not copied to the server bin folder automatically
      I'm working on several ASP.NET projects at the same time. I have a separate web server and each has its own solution folder on my local PC. The...
  3. #2

    Default Re: copy Attachement from Email on server (files copied are not valid)

    "nic den" <ndengler@yahoo.fr> wrote in message
    news:3f587c11$1@news.swissonline.ch...
    > Hi,
    > I'm getting emails from an address trough a script and I want to copy the
    > attached files on the server. I can get the files and copy them on the
    > server (trough the function below) BUT the files are not valid (images
    > cannot be displayed)
    >
    > how can I solve this?
    <snip users untested code>

    Aren't e-mail attachments Base64 encoded?


    Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139