public static function upload(string $path, string $postName = "images", $thumbWidth = 300, $thumbHeight = 300) { $path = FileSystem::getRealPath($path); $response = []; if (isset($_FILES[$postName])) { foreach ($_FILES[$postName]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES[$postName]["tmp_name"][$key]; $name = Etc::sanitize($_FILES[$postName]["name"][$key]); if (move_uploaded_file($tmp_name, "{$path}/{$name}")) { $image = new Image("{$path}/{$name}"); $response[] = ["thumb" => $image->src($thumbWidth, $thumbHeight), "file" => $name]; } } } } return $response; }
public static function deliver($imageFile) { $imageFile = FileSystem::getRealPath($imageFile); if (FileSystem::exists($imageFile)) { $imageInfo = getimagesize($imageFile); switch ($imageInfo[2]) { case IMAGETYPE_JPEG: header("Content-Type: image/jpg", 1); break; case IMAGETYPE_GIF: header("Content-Type: image/gif"); break; case IMAGETYPE_PNG: header("Content-Type: image/png", 1); break; default: break; } // Set the content-length header header('Content-Length: ' . filesize($imageFile)); // Write the image bytes to the client readfile($imageFile); } }
public function realPath() { return FileSystem::getRealPath($this->path); }