Exemplo n.º 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);
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 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);
 }