Mam skrypt do zapisywania załączników za pośrednictwem IMAP. Załączniki są zapisywane oprócz plików txt. Nie wyświetla się nawet błąd. Może ktoś miał podobny problem albo wie w czym jest błąd. Poniżej kod.

  1. <?php
  2.  
  3.  
  4. function parsepart($p,$i){
  5.  global $link,$msgid,$partsarray;
  6.  //where to write file attachments to:
  7.  $filestore = 'pliki/';
  8.  
  9.  //fetch part
  10.  $part=imap_fetchbody($link,$msgid,$i);
  11.  //if type is not text
  12.  if ($p->type!=0){
  13.  //DECODE PART  
  14.  //decode if base64
  15.  if ($p->encoding==3)$part=base64_decode($part);
  16.  //decode if quoted printable
  17.  if ($p->encoding==4)$part=quoted_printable_decode($part);
  18.  //no need to decode binary or 8bit!
  19.  
  20.  //get filename of attachment if present
  21.  $filename='';
  22.  // if there are any dparameters present in this part
  23.  if (count($p->dparameters)>0){
  24.  foreach ($p->dparameters as $dparam){
  25.  if ((strtoupper($dparam->attribute)=='NAME') ||(strtoupper($dparam->attribute)=='FILENAME')) $filename=$dparam->value;
  26.  }
  27.  }
  28.  //if no filename found
  29.  if ($filename==''){
  30.  // if there are any parameters present in this part
  31.  if (count($p->parameters)>0){
  32.  foreach ($p->parameters as $param){
  33.  if ((strtoupper($param->attribute)=='NAME') ||(strtoupper($param->attribute)=='FILENAME')) $filename=$param->value;
  34.  }
  35.  }
  36.  }
  37.  //write to disk and set partsarray variable
  38.  if ($filename!=''){
  39.  $partsarray[$i][attachment] = array('filename'=>$filename,'binary'=>$part);
  40.  $fp=fopen($filestore.$filename,"w+");
  41.  fwrite($fp,$part);
  42.  fclose($fp);
  43.  }
  44.  //end if type!=0  
  45.  }
  46.  
  47.  //if part is text
  48.  else if($p->type==0){
  49.  //decode text
  50.  //if QUOTED-PRINTABLE
  51.  if ($p->encoding==4) $part=quoted_printable_decode($part);
  52.  //if base 64
  53.  if ($p->encoding==3) $part=base64_decode($part);
  54.  
  55.  //OPTIONAL PROCESSING e.g. nl2br for plain text
  56.  //if plain text
  57.  
  58.  if (strtoupper($p->subtype)=='PLAIN')1;
  59.  //if HTML
  60.  else if (strtoupper($p->subtype)=='HTML')1;
  61.  $partsarray[$i][text] = array('type'=>$p->subtype,'string'=>$part);
  62.  }
  63.  
  64.  //if subparts... recurse into function and parse them too!
  65.  if (count($p->parts)>0){
  66.  foreach ($p->parts as $pno=>$parr){
  67.  parsepart($parr,($i.'.'.($pno+1)));  
  68.  }
  69.  }
  70. return;
  71. }
  72. $msgid=1;
  73. //open resource
  74. $link=imap_open("{adres:110/pop3}INBOX", "login", "haslo");
  75.  
  76. //fetch structure of message
  77. $s=imap_fetchstructure($link,$msgid);
  78.  
  79. //see if there are any parts
  80. if (count($s->parts)>0){
  81. foreach ($s->parts as $partno=>$partarr){
  82.  //parse parts of email
  83.  parsepart($partarr,$partno+1);
  84.  }
  85. }
  86.  
  87.  
  88. ?>


z góry dzięki za odpowiedź