Ответов: 2 Просмотров: 103
|
Здравствуйте, я в пхп полный 0 поставили задачу выгружать с почты вложения, я нашел рабочий скрипт только он не выгружает файлы с русским названием.
я понимаю что нужно где то задать параметр iconv UTF-8 а от где и как хз, убил несколько дней на изучение пхп но толку 0.
Помогите пожалуйста.
PHP:
скопировать код в буфер обмена
<?PHP $hostname = '{imap.ukr.net:993/imap/ssl/novalidate-cert}INBOX'; $username = ''; # например somebody@gmail.com $password = ''; $max_emails = 16; if($emails) { $count = 1; foreach($emails as $email_number) { /* get information specific to this email */ /* get mail message */ /* get mail structure */ /* if any attachments found... */ if(isset($structure->parts) && count($structure->parts)) { for($i = 0; $i < count($structure->parts); $i++) { $attachments[$i] = array( 'is_attachment' => false, 'filename' => '', 'name' => '', 'attachment' => '' ); if($structure->parts[$i]->ifdparameters) { foreach($structure->parts[$i]->dparameters as $object) { { $attachments[$i]['is_attachment'] = true; $attachments[$i]['filename'] = $object->value; } } } if($structure->parts[$i]->ifparameters) { foreach($structure->parts[$i]->parameters as $object) { { $attachments[$i]['is_attachment'] = true; $attachments[$i]['name'] = $object->value; } } } if($attachments[$i]['is_attachment']) { $attachments[$i]['attachment'] = imap_fetchbody($inbox, $email_number, $i+1 ); /* 4 = QUOTED-PRINTABLE encoding */ if($structure->parts[$i]->encoding == 3) { $attachments[$i]['attachment'] = base64_decode($attachments[$i]['attachment']); } /* 3 = BASE64 encoding */ elseif($structure->parts[$i]->encoding == 4) { } } } } /* iterate through each attachment and save it */ foreach($attachments as $attachment) { if($attachment['is_attachment'] == 1) { $filename = $attachment['name']; if(empty($filename)) $filename = $attachment['filename']; if(empty($filename)) $filename = time() . "dat"; /* prefix the email number to the filename in case two emails * have the attachment with the same file name. */ $fp = fopen('/mnt/c/ubuntu/pochta/'. $filename, 'w+'); fwrite($fp, $attachment['attachment']); } } if($count++ >= $max_emails) break; } } /* close the connection */ echo "Done\n"; ?>
|