예제 #1
0
 /**
  * Set the path to the file
  * 
  * @param string $path
  * @param string|null $contentType
  */
 public function setPath($path, $contentType = null)
 {
     if (($test = File::isReadable($path)) !== true) {
         throw new InvalidArgumentException("invalid value provided for 'path'; {$test}");
     }
     $this->path = $path;
     if ($contentType === null) {
         $ext = pathinfo($path, PATHINFO_EXTENSION);
         $contentType = Mime::getTypeFromExtension($ext);
     }
     $this->addHeader("Content-Type", $contentType);
 }
예제 #2
0
파일: BodyDecoder.php 프로젝트: sndsgd/http
 protected function createUploadedFile(array $info) : \sndsgd\http\UploadedFile
 {
     if (!isset($info["type"]) || empty($info["type"])) {
         $extension = pathinfo($info["name"], PATHINFO_EXTENSION);
         $info["type"] = \sndsgd\Mime::getTypeFromExtension($extension);
     }
     $file = new \sndsgd\http\UploadedFile($info["name"], $info["type"], $info["size"], $info["tmp_name"], $info["error"]);
     return $file;
 }
예제 #3
0
 /**
  * Stubbable method to read the content type from a file
  *
  * @param string $path
  * @return string
  */
 protected function getContentTypeFromFile(string $path)
 {
     return \sndsgd\Mime::getTypeFromFile($path);
 }