Ejemplo n.º 1
0
 public function testReturnsCurlValueStringAndPostname()
 {
     $file = new PostFile('foo', __FILE__, null, 'NewPostFileTest.php');
     if (version_compare(phpversion(), '5.5.0', '<')) {
         $this->assertContains('@' . __FILE__ . ';filename=NewPostFileTest.php;type=text/x-', $file->getCurlValue());
     } else {
         $c = $file->getCurlValue();
         $this->assertEquals(__FILE__, $c->getFilename());
         $this->assertEquals('NewPostFileTest.php', $c->getPostFilename());
         $this->assertContains('text/x-', $c->getMimeType());
     }
 }
 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 public function testReturnsCurlValueString()
 {
     $file = new PostFile('foo', __FILE__);
     $this->assertContains('@' . __FILE__ . ';type=text/x-', $file->getCurlString());
 }