Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

MultipartBody.php

Zuletzt modifiziert: 09.10.2024, 12:57 - Dateigröße: 2.91 KiB


001  <?php
002  namespace GuzzleHttp\Post;
003   
004  use GuzzleHttp\Stream\AppendStream;
005  use GuzzleHttp\Stream\Stream;
006  use GuzzleHttp\Stream\StreamDecoratorTrait;
007  use GuzzleHttp\Stream\StreamInterface;
008   
009  /**
010   * Stream that when read returns bytes for a streaming multipart/form-data body
011   */
012  class MultipartBody implements StreamInterface
013  {
014      use StreamDecoratorTrait;
015   
016      private $boundary;
017   
018      /**
019       * @param array  $fields   Associative array of field names to values where
020       *                         each value is a string or array of strings.
021       * @param array  $files    Associative array of PostFileInterface objects
022       * @param string $boundary You can optionally provide a specific boundary
023       * @throws \InvalidArgumentException
024       */
025      public function __construct(
026          array $fields = [],
027          array $files = [],
028          $boundary = null
029      ) {
030          $this->boundary = $boundary ?: uniqid();
031          $this->stream = $this->createStream($fields, $files);
032      }
033   
034      /**
035       * Get the boundary
036       *
037       * @return string
038       */
039      public function getBoundary()
040      {
041          return $this->boundary;
042      }
043   
044      public function isWritable()
045      {
046          return false;
047      }
048   
049      /**
050       * Get the string needed to transfer a POST field
051       */
052      private function getFieldString($name, $value)
053      {
054          return sprintf(
055              "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n",
056              $this->boundary,
057              $name,
058              $value
059          );
060      }
061   
062      /**
063       * Get the headers needed before transferring the content of a POST file
064       */
065      private function getFileHeaders(PostFileInterface $file)
066      {
067          $headers = '';
068          foreach ($file->getHeaders() as $key => $value) {
069              $headers .= "{$key}{$value}\r\n";
070          }
071   
072          return "--{$this->boundary}\r\n" . trim($headers) . "\r\n\r\n";
073      }
074   
075      /**
076       * Create the aggregate stream that will be used to upload the POST data
077       */
078      protected function createStream(array $fields, array $files)
079      {
080          $stream = new AppendStream();
081   
082          foreach ($fields as $name => $fieldValues) {
083              foreach ((array) $fieldValues as $value) {
084                  $stream->addStream(
085                      Stream::factory($this->getFieldString($name, $value))
086                  );
087              }
088          }
089   
090          foreach ($files as $file) {
091   
092              if (!$file instanceof PostFileInterface) {
093                  throw new \InvalidArgumentException('All POST fields must '
094                      . 'implement PostFieldInterface');
095              }
096   
097              $stream->addStream(
098                  Stream::factory($this->getFileHeaders($file))
099              );
100              $stream->addStream($file->getContent());
101              $stream->addStream(Stream::factory("\r\n"));
102          }
103   
104          // Add the trailing boundary with CRLF
105          $stream->addStream(Stream::factory("--{$this->boundary}--\r\n"));
106   
107          return $stream;
108      }
109  }
110