Add a POST file to the upload
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.
EntityEnclosingRequestInterface
Overrides EntityEnclosingRequestInterface::addPostFile
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;
}