領収証発行サービス
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.1KB

  1. <?php
  2. namespace App\Files;
  3. use Illuminate\Support\Facades\Storage;
  4. use Illuminate\Support\Str;
  5. class TmpFile
  6. {
  7. protected const DIR = "/tmp";
  8. protected string $uuid;
  9. public function __construct()
  10. {
  11. $this->uuid = Str::uuid();
  12. }
  13. public function __destruct()
  14. {
  15. // ファイルダウンロード前に削除されては困るので処理をコメントアウトしている
  16. // if (Storage::exists($this->getPath())) {
  17. // Storage::delete($this->getPath());
  18. // }
  19. }
  20. public function getPath()
  21. {
  22. return static::DIR . "/" . $this->uuid;
  23. }
  24. public function getFullPath()
  25. {
  26. return Storage::path($this->getPath());
  27. }
  28. public function put(string $content)
  29. {
  30. Storage::put($this->getPath(), $content);
  31. }
  32. public function append(string $content)
  33. {
  34. Storage::append($this->getPath(), $content);
  35. }
  36. public function download(string $name = "download")
  37. {
  38. return response()->download($this->getFullPath(), $name)->deleteFileAfterSend();
  39. }
  40. }