public function addPostFile($field, $filename = null, $contentType = null, $postname = null) { $data = null; if ($field instanceof PostFileInterface) { $data = $field; } elseif (is_array($filename)) { foreach ($filename as $file) { $this->addPostFile($field, $file, $contentType); } return $this; } elseif (!is_string($filename)) { throw new RequestException('The path to a file must be a string'); } elseif (!empty($filename)) { $data = new PostFile($field, $filename, $contentType, $postname); } if ($data) { if (!isset($this->postFiles[$data->getFieldName()])) { $this->postFiles[$data->getFieldName()] = array($data); } else { $this->postFiles[$data->getFieldName()][] = $data; } $this->processPostFields(); } return $this; }
public function addPostFile($field, $filename = null, $contentType = null) { $data = null; if ($field instanceof PostFileInterface) { $data = $field; } elseif (is_array($filename)) { // Allow multiple values to be set in a single key foreach ($filename as $file) { $this->addPostFile($field, $file, $contentType); } return $this; } 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; }
public function testCanChangeFieldName() { $file = new PostFile('foo', '@' . __FILE__); $file->setFieldName('Boo'); $this->assertEquals('Boo', $file->getFieldName()); }