/**
  * _makeMultipartContent
  * 
  * @method _makeMultipartContent
  * @param array $contents
  * @param string $boundary
  * @return string 
  */
 private static function _makeMultipartContent(array $contents, $boundary)
 {
     $rows = array('--' . $boundary);
     foreach ($contents as $key => $value) {
         $rows[] = 'Content-Disposition: form-data; name="' . $key . '"';
         if (is_array($value) && isset($value['file']) || 0 === strpos($value, '@') && file_exists($file = substr($value, 1))) {
             $type = $encoding = $content = $name = null;
             if (is_array($value)) {
                 if (isset($value['file'])) {
                     $file = $value['file'];
                 } else {
                     $file = null;
                 }
                 if (isset($value['name'])) {
                     $name = $value['name'];
                 }
                 if (isset($value['content'])) {
                     $content = $value['content'];
                 }
                 if (isset($value['type'])) {
                     $type = $value['type'];
                 }
                 if (isset($value['encoding'])) {
                     $encoding = $value['encoding'];
                 }
             }
             if (!$type && $file) {
                 $type = AttoMimeType::getByFileName($file);
             }
             if (!$encoding && $type) {
                 if (!starts_with('text', $type) && !ends_with('xml', $type) && !ends_with('json', $type) && !ends_with('script', $type)) {
                     $encoding = 'binary';
                 }
             }
             if (!$name && $file) {
                 $name = basename($file);
             }
             if ($name) {
                 $rows[count($rows) - 1] .= '; filename=' . $name;
             }
             if ($type) {
                 $rows[] = 'Content-Type: ' . $type;
             }
             if ($encoding) {
                 $rows[] = 'Content-Transfer-Encoding: ' . $encoding;
             }
             if ($file) {
                 $value = file_get_contents($file);
             } else {
                 $value = $content;
             }
         }
         $rows[] = '';
         $rows[] = $value;
         $rows[] = '--' . $boundary;
     }
     $rows[] = '';
     return implode("\r\n", $rows);
 }
Exemple #2
0
 /**
  * setContentType
  * 
  * @method setContentType
  * @param {string} $typealue defaulet is text/html
  * @param {string} $charset defaulet is utf-8
  */
 public static function setContentType($type = 'text/html', $charset = 'utf-8')
 {
     if (strpos($type, '/') === false) {
         $byext = AttoMimeType::getByExtension($type);
         $type = $byext ? $byext : $type;
     }
     self::setHeader('Content-Type', $type . ($charset ? ';charset=' . $charset : ''));
 }