當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Am_HttpRequest::addUpload方法代碼示例

本文整理匯總了PHP中Am_HttpRequest::addUpload方法的典型用法代碼示例。如果您正苦於以下問題:PHP Am_HttpRequest::addUpload方法的具體用法?PHP Am_HttpRequest::addUpload怎麽用?PHP Am_HttpRequest::addUpload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Am_HttpRequest的用法示例。


在下文中一共展示了Am_HttpRequest::addUpload方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: _sendMail

 protected function _sendMail()
 {
     $request = new Am_HttpRequest(self::API_ENDPOINT, Am_HttpRequest::METHOD_POST);
     $params = array();
     $params['api_user'] = $this->_api_user;
     $params['api_key'] = $this->_api_key;
     $part = new Zend_Mail_Part(array('raw' => $this->header . Zend_Mime::LINEEND . $this->body));
     $this->_extractHeaderToParams($part, 'to', $params);
     $this->_extractHeaderToParams($part, 'cc', $params);
     $this->_extractHeaderToParams($part, 'bcc', $params);
     $this->_extractHeaderToParams($part, 'from', $params, false);
     $this->_extractHeaderToParams($part, 'reply-to', $params, false);
     $subject = $part->getHeader('subject');
     if (strpos($subject, '=?') === 0) {
         $subject = mb_decode_mimeheader($subject);
     }
     $params['subject'] = $subject;
     $canHasAttacments = false;
     //message
     list($type) = explode(";", $part->getHeader('content-type'));
     if ($type == 'multipart/alternative') {
         $msgPart = $part->getPart(2);
     } else {
         $msgPart = $part->isMultipart() ? $part->getPart(1) : $part;
         if ($msgPart->isMultipart()) {
             $msgPart = $msgPart->getPart(2);
             //html part
         }
         $canHasAttacments = true;
     }
     list($type) = explode(";", $msgPart->getHeader('content-type'));
     $encoding = $msgPart->getHeader('content-transfer-encoding');
     $content = $msgPart->getContent();
     if ($encoding && $encoding == 'quoted-printable') {
         $content = quoted_printable_decode($content);
     } else {
         $content = base64_decode($content);
     }
     switch ($type) {
         case 'text/plain':
             $params['text'] = $content;
             break;
         case 'text/html':
             $params['html'] = $content;
             break;
         default:
             throw new Zend_Mail_Transport_Exception("SendGrid API: unknown content-type: " . $type);
     }
     //attachments
     $handlers = array();
     if ($canHasAttacments) {
         if ($part->isMultipart()) {
             $params['files'] = array();
             for ($i = 2; $i <= $part->countParts(); $i++) {
                 $attPart = $part->getPart($i);
                 $encoding = $attPart->getHeader('content-transfer-encoding');
                 $disposition = $attPart->getHeader('content-disposition');
                 preg_match('/filename="(.*)"/', $disposition, $m);
                 $filename = $m[1];
                 $content = $attPart->getContent();
                 if ($encoding && $encoding == 'quoted-printable') {
                     $content = quoted_printable_decode($content);
                 } else {
                     $content = base64_decode($content);
                 }
                 $f = tmpfile();
                 array_push($handlers, $f);
                 fwrite($f, $content);
                 $request->addUpload("files[{$filename}]", $f, $filename);
             }
         }
     }
     $request->addPostParameter($params);
     $response = $request->send();
     foreach ($handlers as $f) {
         fclose($f);
     }
     if ($response->getStatus() != 200) {
         throw new Zend_Mail_Transport_Exception("SendGrid API: unexpected response: " . $response->getBody());
     }
 }
開發者ID:alexanderTsig,項目名稱:arabic,代碼行數:81,代碼來源:Mail.php


注:本文中的Am_HttpRequest::addUpload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。