Précédent   Forum des professionnels en informatique > PHP > Bibliothèques et frameworks
Bibliothèques et frameworks Forum d'entraide sur les frameworks, templates, bibliothèques de code (PDFLib, eZPdf, JpGraph, Artichow, PEAR, etc). Avant de poster : FAQ bibliothèques, toutes les FAQ PHP et cours bibliothèques
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 09/05/2006, 10h59   #1
Futur Membre du Club
 
Inscription : octobre 2003
Messages : 99
Détails du profil
Informations forums :
Inscription : octobre 2003
Messages : 99
Points : 16
Points : 16
Par défaut [Librairies] Comment uploader un fichier via email ?

Salut !

Je veux écrire un code qui fait un upload d'une image envoyée via email en se servant du sujet du message (ou pourquoi pas du contenu lui même)pour sauvegarder l'image sur mon serveur web.


Est-ce possible ? Si oui comment y arriver ? Avez-vous des astuces, sites web etc... qui en parlent ?

Merci pour votre aide !

Stéphane
pdtor est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/05/2006, 11h27   #2
Nouveau Membre du Club
 
Avatar de pymouse
 
Homme
Ingénieur développement logiciels
Inscription : décembre 2004
Messages : 128
Détails du profil
Informations personnelles :
Sexe : Homme
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : décembre 2004
Messages : 128
Points : 36
Points : 36
Voila un petit bout de code de mon Webmail :

Code :
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
 
# fonction CHECK_PART #
function Check_Part($part,$id){
    global $attachments, $debug, $debug_depth, $dispos; $ans=sizeof($attachments);
    doDebug("+Checking part $id");
    $debug_depth++;
    doDebug("Parttype=".$part->type ."/". $part->subtype);
 
    if($part->ifdisposition){ $dispos++; doDebug("<b>Disposition</b>"); }
    if($part->ifdescription){ doDebug("<b>Description=".$part->description."</b>"); }
 
     switch($part->type){
       case 1: if((strtolower($part->subtype) == "mixed")
                   or (strtolower($part->subtype)  == "alternative")
                   or (strtolower($part->subtype) == "related")) break;
 
       default: $an = sizeof($attachments);
               if($part->ifdparameters){
                   $dpara = $part->dparameters;
                   for ($v=0;$v<sizeof($dpara);$v++){
                     if (eregi("filename", $dpara[$v]->attribute))
                         $fname = $dpara[$v]->value;}
               }
               if($part->ifparameters){
                   if(empty($fname)){
                     $para = $part->parameters;
                     for ($v=0;$v<sizeof($para);$v++){
                         if (eregi("name", $para[$v]->attribute)) $fname = $para[$v]->value;
                     }
                   }
               }
               if(empty($fname))$fname = "(no name)";
 
             $attachments[$an]->id = ($an+1);
             $attachments[$an]->part = $id;
             $attachments[$an]->filename = $fname;
             $attachments[$an]->type = $part->type;
             $attachments[$an]->subtype = $part->subtype;
             $attachments[$an]->dispos = $dispos;
             $attachments[$an]->size = $part->bytes;
             $attachments[$an]->encod = $part->encoding;
             doDebug("Filename=".$attachments[$an]->filename); break;
     }
 
    for($x = 0; $x < count($part->parts); $x++){
     $attachments = Check_Part($part->parts[$x], $id.".".($x+1));
    }
    if($part->ifdisposition) $dispos--;
    $debug_depth--;
    doDebug("-End of part $id");
    return $attachments;
}
 
# fonction DECODE_MAIL #
function decode_mail($mbox, $msg){
    global $attachments, $debug, $debug_depth;
    doDebug("+Decoding message $msg"); $debug_depth++;
    $obj = imap_fetchstructure($mbox, $msg, FT_UID); $moet_werken=true; $id=1;
    while($moet_werken){
     $attachments = Check_Part($obj, $id);
 
     $moet_werken=false;
    }
    $debug_depth--; doDebug("-End of message $msg");
 
    return $attachments;
}
 
# ouverture de la boite mail #
$mbox = open_mailbox($server, $login, $pass);
 
# nombre de mails #
$mailcheck = imap_check($mbox);
$mailnumber = $mailcheck->Nmsgs;
 
# on parcours tous les mails #
$overview = imap_fetch_overview($mbox,"1:$mailnumber",0);
$nbm = sizeof($overview);
 
for($i= $nbm-1; $i >= 0; $i--)
        {
            $val = $overview[$i];
            $nb = $val->msgno;
            $rawsubject = imap_mime_header_decode($val->subject);
            $subject = $rawsubject[0]->text;
            if($subject == '') {$subject = "(no subject)";};
 
            # Decodage du mail #
            $attachments = decode_mail($mbox,$nb);
 
            # Récupération du corps et des pieces jointes #
            for($x = 0; $x < sizeof($attachments); $x++)
            {
                if($x == 0)
                {    # corp du mail$ #
                    $db_body = imap_fetchbody($mbox,$nb, $attachments[$x]->id);
                    $db_body_type = $attachments[$x]->subtype;
                    if($attachments[$x]->encod == 1) $db_body = imap_8bit($db_body); 
                    if($attachments[$x]->encod == 2) $db_body = imap_binary($db_body);
                    if($attachments[$x]->encod == 3) $db_body = imap_base64($db_body); 
                    if($attachments[$x]->encod == 4) $db_body = imap_qprint($db_body); 
                    $type_mess = $attachments[$x]->type;
                }
                else
                {   # piece jointe #
                    $return_content = imap_fetchbody($mbox,$nb, $attachments[$x]->id);
                    if($attachments[$x]->encod == 1) $return_content = imap_8bit($return_content); 
                    if($attachments[$x]->encod == 2) $return_content = imap_binary($return_content);
                    if($attachments[$x]->encod == 3) $return_content = imap_base64($return_content); 
                    if($attachments[$x]->encod == 4) $return_content = imap_qprint($return_content); 
 
 
                    //echo $nom_fichier;
                    $pj_type = $attachments[$x]->type;
 
                    if($attachments[$x]->filename != '' && $attachments[$x]->filename != '(no name)')
                    {    
                        $nom_fichier = $attachments[$x]->filename;
                        # création de la piece jointe #
                        $link = REPERTOIRE."/".$nom_fichier;
                        //echo $db_link_pj;
                        $newfichier = fopen($link,"w+");
                        # Ecriture dans le fichier #
                        fwrite($newfichier,$return_content);
                        # Fermeture du fichier #
                        fclose($newfichier);
                    }
                }
            }; // for x
    }; /// for nbm
Ici je parcours tous les mails et enregistre les pieces jointes dans un dossier : REPERTOIRE ( c:/../.. ) .

J'espere que cela va t'aider.
pymouse est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/05/2006, 11h33   #3
Futur Membre du Club
 
Inscription : octobre 2003
Messages : 99
Détails du profil
Informations forums :
Inscription : octobre 2003
Messages : 99
Points : 16
Points : 16
Par défaut Re: Comment uploader un fichier via email ?

Merci pour le code, il semble que cela m'aidera assez. Mais je voudrais savoir comment je pourrais lancer ce code lorsque l'email est reçu ?
pdtor est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 12h01.


 
 
 
 
Partenaires

Hébergement Web