DownAppController.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. /** 下载 */
  3. namespace App\Http\Controllers;
  4. use App\Http\Requests\StoreRequest;
  5. use App\Service\DataService;
  6. use http\Env\Response;
  7. use phpDocumentor\Reflection\File;
  8. use Illuminate\Session\Store;
  9. use Illuminate\Support\Facades\Storage;
  10. use Illuminate\Support\Facades\Input;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\DB;
  13. class DownAppController extends Controller
  14. {
  15. public function showdown($id = 13)
  16. {
  17. if ($id !== 13) {
  18. $data = DB::table('admin_app')->where('id', $id)->first();
  19. $data = get_object_vars($data);//转数组
  20. $img = $data['img'];
  21. if (strpos($img, '|') == false) {
  22. $data['img'] = $img;
  23. $data['img1'] = $img;
  24. } else {
  25. $data['img1'] = substr($img, 0, strrpos($img, '|'));
  26. $data['img'] = substr($img, strripos($img, '|') + 1);
  27. }
  28. return view('index.dewnloads', compact('data'));
  29. } else {
  30. $id = DB::table('admin_app')->orderBy('id', 'desc')->select('id')->first();
  31. //这里是没有id的
  32. $id = get_object_vars($id);
  33. $id = $id['id'];
  34. $data = DB::table('admin_app')->where('id', $id)->first();
  35. $data = get_object_vars($data);//转数组
  36. $img = $data['img'];
  37. if (strpos($img, '|') == false) {
  38. $data['img'] = $img;
  39. $data['img1'] = $img;
  40. } else {
  41. $data['img1'] = substr($img, 0, strrpos($img, '|'));
  42. $data['img'] = substr($img, strripos($img, '|') + 1);
  43. }
  44. return view('index.dewnloads', compact('data'));
  45. }
  46. }
  47. public function downloads($id,Request $request){
  48. $filepath = DB::table('admin_app')->where('id',$id)->select('path')->first();
  49. if($filepath != null || $filepath!=''){
  50. $filename = DB::table('admin_app')->where('id',$id)->select('app_title')->first();
  51. $filepath = get_object_vars($filepath);
  52. $filename = get_object_vars($filename);
  53. $filename = $filename['app_title'];
  54. $filepath = $filepath['path'];
  55. return response()->download($filepath,$filename);
  56. }else{
  57. return redirect('/');
  58. }
  59. }
  60. }