AttachmentController.php 1018 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Http\Controllers\Web;
  3. use App\Models\BaseAttachmentModel;
  4. use Response;
  5. class AttachmentController extends Controller
  6. {
  7. public function download($md5)
  8. {
  9. $attachment = BaseAttachmentModel::where(['md5' => $md5])->first();
  10. if (!$attachment) {
  11. return view('errors.404');
  12. }
  13. return Response::download($attachment->path, $attachment->name, [
  14. 'Content-type' => $attachment->file_type,
  15. 'Accept-Ranges' => 'bytes',
  16. 'Accept-Length' => $attachment->size,
  17. ]);
  18. }
  19. public function image($md5)
  20. {
  21. $attachment = BaseAttachmentModel::where(['md5' => $md5])->first();
  22. if (!$attachment) {
  23. return view('errors.404');
  24. }
  25. return Response::download($attachment->path, $attachment->name, [
  26. 'Content-type' => $attachment->file_type,
  27. 'Accept-Ranges' => 'bytes',
  28. 'Accept-Length' => $attachment->size,
  29. ], 'inline');
  30. }
  31. }