|
Posted by aurelien_v on 10/13/11 11:30
Hi, I currently develop a webmail but i have a serious problem with
attachment.
In fact, the size of all attachment is 2 octect !!! and are corrupt.
and when i put a test in the code to know the existance of the file, i
have the answer "File not found" And the file is empty.
Can you help me please ?
(PHP 5 and IE 6).
Thank you very much.
<?php
if(isset($_GET["id"])) $id = $_GET["id"];
if(isset($_GET["id"])) $pid = $_GET["pid"];
//Prevoir message d'erreur
//Connection au serveur
$boite = "INBOX";
$serveur_entrant = "pop3.worldonline.fr";
$port = ":110";
$protocole = "/pop3/notls";
$identifiant = "aurelien_v%worldonline.fr";
$mot_de_passe = "242g4350";
$nb_mail_par_page = 10;
$inbox =
imap_open("{".$serveur_entrant.$port.$protocole."}",$identifiant,$mot_de_passe);
$nb_message = imap_num_msg($inbox);
//collecte des informations concernant le mail
$entete= imap_headerinfo($inbox,$id);
$structure = imap_fetchstructure($inbox,$id);
/// FICHIER ATTACHES
$tableau = recherche_attachement($structure);
//LECTURE DE LA PIECE JOINTE
for($x=0; $x<sizeof($tableau); $x++)
{
if ($tableau[$x]["pid"]== $pid)
{
$type = $tableau[$x]["type"];
$encoding = $tableau[$x]["encoding"];
$filename = $tableau[$x]["name"];
$size = $tableau[$x]["size"];
}
}
$attachement = imap_fetchbody($inbox,$id,$pid);
//echo $filename."<br>";
//echo $type."<br>";
//echo $size."<br>";
//echo $encoding ;
header ("Pragma: public");
header ("Cache-control: no-store, max-age=0,
no-cache,
must-revalidate");
header ("Cache-control: post-check=0,
pre-check=0",false);
header ("Cache-control: private");
header("Content-lenght: $size");
header("Content-Type: $type");
header("Content-Disposition:attachment;
filename=\"$filename\"");
//---------------------
imap_close($inbox);
//-------------------------------------------------------
//----------------- FONCTIONS ---------------------------
//-------------------------------------------------------
//---------- TABLEAU DES FICHIERS ATTACHES -----------
function recherche_attachement($structure)
{
$type =
array("text","multipart","message","application","audio","image","video","autre");
$encoding =
array("7bit","8bit","binary","base64","quoted-printable","autre");
$tab = array();
//Si le message est de type MULTIPART
if ($structure->type == 1)
{
//On découpe le mail en parties
$toutes_parties = ($structure->parts);
//On extrait partie par partie pour les
analyser
for ($i=0; $i<sizeof($toutes_parties); $i++)
{
//on se place sur une partie
$partie = $toutes_parties[$i];
//Verification de l'existence de
disposition
if ($partie->ifdisposition == true)
{
//On récupère le type de disposition
$disposition = $partie->disposition;
//On analyse le résultat de la
disposition
if ($disposition ==
"ATTACHMENT")
{
$params = $partie->dparameters;
foreach ($params as $p)
{
if ($p->attribute == "FILENAME")
{
$tab[$i]["pid"] = ($i+1);
$tab[$i]["name"] = $p->value;
$tab[$i]["size"] = $partie->bytes;
$tab[$i]["type"] = $type[$partie->type] . "/" .
strtolower($partie->subtype);
$tab[$i]["encoding"] =
$encoding[$partie->encoding];
break;
}
}
}
}
else
{
$tab[$i]["pid"]
= ($i+1);
$tab[$i]["disposition"] = "";
$tab[$i]["name"] = "";
$tab[$i]["size"] = "";
$tab[$i]["type"] = "";
$tab[$i]["encoding"] = "";
}
}
}
return $tab;
}
?>
Navigation:
[Reply to this message]
|