public function EntityEnclosingRequest::addPostFile

Add a POST file to the upload

Parameters

string $field POST field to use (e.g. file). Used to reference content from the server.:

string $filename Full path to the file. Do not include the @ symbol.:

string $contentType Optional Content-Type to add to the Content-Disposition.: Default behavior is to guess. Set to false to not specify.

Return value

EntityEnclosingRequestInterface

Overrides EntityEnclosingRequestInterface::addPostFile

1 call to EntityEnclosingRequest::addPostFile()
EntityEnclosingRequest::addPostFiles in drupal/core/vendor/guzzle/http/Guzzle/Http/Message/EntityEnclosingRequest.php
Add POST files to use in the upload

File

drupal/core/vendor/guzzle/http/Guzzle/Http/Message/EntityEnclosingRequest.php, line 235

Class

EntityEnclosingRequest
HTTP request that sends an entity-body in the request message (POST, PUT, PATCH, DELETE)

Namespace

Guzzle\Http\Message

Code

public function addPostFile($field, $filename = null, $contentType = null) {
  $data = null;
  if ($field instanceof PostFileInterface) {
    $data = $field;
  }
  elseif (!is_string($filename)) {
    throw new RequestException('The path to a file must be a string');
  }
  elseif (!empty($filename)) {

    // Adding an empty file will cause cURL to error out
    $data = new PostFile($field, $filename, $contentType);
  }
  if ($data) {
    if (!isset($this->postFiles[$data
      ->getFieldName()])) {
      $this->postFiles[$data
        ->getFieldName()] = array(
        $data,
      );
    }
    else {
      $this->postFiles[$data
        ->getFieldName()][] = $data;
    }
    $this
      ->processPostFields();
  }
  return $this;
}