1:修改框架config下的文件filesystems.php中的配置;

  1. 原文件
  2. <?php
  3.  
  4. return [
  5.  
  6. /*
  7. |--------------------------------------------------------------------------
  8. | Default Filesystem Disk
  9. |--------------------------------------------------------------------------
  10. |
  11. | Here you may specify the default filesystem disk that should be used
  12. | by the framework. The "local" disk, as well as a variety of cloud
  13. | based disks are available to your application. Just store away!
  14. |
  15. */
  16.  
  17. 'default' => env('FILESYSTEM_DRIVER', 'local'),
  18.  
  19. /*
  20. |--------------------------------------------------------------------------
  21. | Default Cloud Filesystem Disk
  22. |--------------------------------------------------------------------------
  23. |
  24. | Many applications store files both locally and in the cloud. For this
  25. | reason, you may specify a default "cloud" driver here. This driver
  26. | will be bound as the Cloud disk implementation in the container.
  27. |
  28. */
  29.  
  30. 'cloud' => env('FILESYSTEM_CLOUD', 's3'),
  31.  
  32. /*
  33. |--------------------------------------------------------------------------
  34. | Filesystem Disks
  35. |--------------------------------------------------------------------------
  36. |
  37. | Here you may configure as many filesystem "disks" as you wish, and you
  38. | may even configure multiple disks of the same driver. Defaults have
  39. | been setup for each driver as an example of the required options.
  40. |
  41. | Supported Drivers: "local", "ftp", "sftp", "s3"
  42. |
  43. */
  44.  
  45. 'disks' => [
  46.  
  47. 'local' => [
  48. 'driver' => 'local',
  49. 'root' => storage_path('app'),
  50. ],
  51.  
  52. 'public' => [
  53. 'driver' => 'local',
  54. 'root' => storage_path('app/public'),
  55. 'url' => env('APP_URL').'/storage',
  56. 'visibility' => 'public',
  57. ],
  58.  
  59. 's3' => [
  60. 'driver' => 's3',
  61. 'key' => env('AWS_ACCESS_KEY_ID'),
  62. 'secret' => env('AWS_SECRET_ACCESS_KEY'),
  63. 'region' => env('AWS_DEFAULT_REGION'),
  64. 'bucket' => env('AWS_BUCKET'),
  65. 'url' => env('AWS_URL'),
  66. ],
  67.  
  68. ],
  69.  
  70. /*
  71. |--------------------------------------------------------------------------
  72. | Symbolic Links
  73. |--------------------------------------------------------------------------
  74. |
  75. | Here you may configure the symbolic links that will be created when the
  76. | `storage:link` Artisan command is executed. The array keys should be
  77. | the locations of the links and the values should be their targets.
  78. |
  79. */
  80.  
  81. 'links' => [
  82. public_path('storage') => storage_path('app/public'),
  83. ],
  84.  
  85. ];
  1. 修改的文件
  1. <?php

    return [

    /*
    |--------------------------------------------------------------------------
    | Default Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Here you may specify the default filesystem disk that should be used
    | by the framework. The "local" disk, as well as a variety of cloud
    | based disks are available to your application. Just store away!
    |
    */

    'default' => env('FILESYSTEM_DRIVER', 'local'),

    /*
    |--------------------------------------------------------------------------
    | Default Cloud Filesystem Disk
    |--------------------------------------------------------------------------
    |
    | Many applications store files both locally and in the cloud. For this
    | reason, you may specify a default "cloud" driver here. This driver
    | will be bound as the Cloud disk implementation in the container.
    |
    */

    'cloud' => env('FILESYSTEM_CLOUD', 's3'),

    /*
    |--------------------------------------------------------------------------
    | Filesystem Disks
    |--------------------------------------------------------------------------
    |
    | Here you may configure as many filesystem "disks" as you wish, and you
    | may even configure multiple disks of the same driver. Defaults have
    | been setup for each driver as an example of the required options.
    |
    | Supported Drivers: "local", "ftp", "sftp", "s3"
    |
    */

    'disks' => [

    'local' => [
    'driver' => 'local',
    'root' => public_path(),
    ],


    'public' => [
    'driver' => 'local',
    'root' => public_path(),
    'url' => env('APP_URL').'/storage',
    'visibility' => 'public',
    ],

    's3' => [
    'driver' => 's3',
    'key' => env('AWS_ACCESS_KEY_ID'),
    'secret' => env('AWS_SECRET_ACCESS_KEY'),
    'region' => env('AWS_DEFAULT_REGION'),
    'bucket' => env('AWS_BUCKET'),
    'url' => env('AWS_URL'),
    ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Symbolic Links
    |--------------------------------------------------------------------------
    |
    | Here you may configure the symbolic links that will be created when the
    | `storage:link` Artisan command is executed. The array keys should be
    | the locations of the links and the values should be their targets.
    |
    */

    'links' => [
    public_path('storage') => storage_path('app/public'),
    public_path('img') => public_path('img'),
    ],

    ];
  1.  

然后书写路由:

  1. Route::group(['namespace' => 'exam1'], function(){
  2. // 菜单添加
  3. Route::get('create','ExamController@create');
  4. // 菜单保存
  5. Route::post('store','ExamController@store');
  6. // 菜单展示
  7. Route::get('index','ExamController@index');
  8. // 菜单删除
  9. Route::get('del/{id}','ExamController@del');
  10. });

视图:

  1. <div class="row cl">
  2. <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>图片:</label>
  3. <div class="formControls col-xs-8 col-sm-9">
  4. <input type="file" class="input-text" value="" placeholder="" id="adminName" name="img">
  5. </div>
  6. </div>

添加至控制器store方法中:

  1. public function store(Request $request){
  2. // 接值
  3. $params=$request->except('_token');
  4. // 文件上传
  5. $img=$request->file('img');
  6. // 保存文件
  7. $params['img']=$img->store(date('Y-m-d')."/".'img');
  8. $params['img']="/".$params['img'];
  9. /*文件上传
  10. * $path= url('').'/'. $img->store('img');
  11. $params['img']=$path;
  12. * */
  13. //添加入库
  14. $res=Exam::create($params);
  15. if (!$res){
  16. return redirect('create')->withErrors(['error'=>'添加失败']);
  17. }
  18. return redirect('index')->with(['success'=>'添加成功']);
  19.  
  20. }

列表展示“:

  1. <tbody>
  2. @foreach($data as $item)
  3. <tr class="text-c">
  4. <td>{{$item->id}}</td>
  5. <td>{{$item->name}}</td>
  6. <td>{{$item->categoy}}</td>
  7. {{-- <td><img src="{{\Illuminate\Support\Facades\URL::asset($item->img)}}" alt=""></td>--}}
  8. <td><img src="{{$item->img}}" alt="" style="width: 100px" height="100px"></td>
  9. <td>{{$item->price}}</td>
  10. <td><a href="/del/{{$item->id}}">删除</a></td>
  11. {{-- <td class="f-14 td-manage"><a style="text-decoration:none" onClick="article_stop(this,'10001')" href="javascript:;" title="下架">--}}
  12. {{-- <i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="article_edit('资讯编辑','article-add.html','10001')" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="article_del(this,{{$item->id}})" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a></td>--}}
  13. </tr>
  14. @endforeach
  15. </tbody>

效果图:

laravel7 图片上传及视图显示的更多相关文章

  1. springmvc的图片上传与导出显示

    1.前端文件上传需要在form表单内添加enctype="multipart/form-data" ,以二进制传递: 2.web.xml文件内配置 <servlet-mapp ...

  2. 微擎 plugin 时间插件 图片上传插件不显示 报错 影响下面执行

    可能是版本更新导致的,之前可能不需要 load()->func('tpl');这个方法 现在加上 load()->func('tpl');应该就可以了

  3. input file 图片上传

    使用第三方:jquery.ajaxfileupload.jsinput中的name根据后端来定 <form method="post" enctype="multi ...

  4. DWZ集成的xhEditor编辑器浏览本地图片上传的设置

    有关xhEditor的文件上传配置官方文档链接:http://i.hdu.edu.cn/dcp/dcp/comm/xheditor/demos/demo08.html 一.xhEditor图片上传的配 ...

  5. Silverlight中的拖拽实现的图片上传

    原文 http://blog.csdn.net/dujingjing1230/article/details/5443003 在Silverlight中因为可以直接从系统的文件夹里面拖出来一个文件直接 ...

  6. Django文件上传【单个/多个图片上传】

    准备工作 python:3.6.8 django:2.2.1 新建django项目 确定项目名称.使用的虚拟环境[当然这个也可以后期修改].app的名称 创建成功,选择在新的窗口中打开 图片上传 修改 ...

  7. html5 图片上传,支持图片预览、压缩、及进度显示,兼容IE6+及标准浏览器

    以前写过上传组件,见 打造 html5 文件上传组件,实现进度显示及拖拽上传,兼容IE6+及其它标准浏览器,对付一般的上传没有问题,不过如果是上传图片,且需要预览的话,就力有不逮了,趁着闲暇时间,给上 ...

  8. springmvc上传图片并显示图片--支持多图片上传

    实现上传图片功能在Springmvc中很好实现.现在我将会展现完整例子. 开始需要在pom.xml加入几个jar,分别是: <dependency> <groupId>comm ...

  9. MVC图片上传并显示缩略图

    前面已经说了怎么通过MVC来上传文件,那么这次就说说如何上传图片然后显示缩略图,这个的实用性还是比较大.用UpLoad文件夹来保存上传的图片,而Temp文件夹来保存缩略图,前面文件上传部分就不再重复了 ...

随机推荐

  1. Java基础(十一)——反射

    一.概述 1.介绍 Reflection(反射)是被视为动态语言的关键,反射机制允许程序在执行期借助于Reflection API取得任何类的内部信息,并能直接操作任意对象的内部属性及方法. 加载完类 ...

  2. js 利用||和&&赋值小技巧

    感谢原文作者:nayi_224 原文链接:https://blog.csdn.net/nayi_224/article/details/80437329 对于需要返回boolean类型数值的地方,比如 ...

  3. NFS(Network File System)即网络文件系统 (转)

    第1章 NFS介绍 1.1 NFS服务内容的概述 □ RPC服务知识概念介绍说明,以及RPC服务存在价值(必须理解掌握) □ NFS服务工作原理讲解(必须理解掌握) □ NFS共享文件系统使用原理讲解 ...

  4. Java GUI 简单台球游戏模型

    完成效果: 1 package com.neuedu.test; 2 3 import java.awt.Frame; 4 import java.awt.Graphics; 5 import jav ...

  5. cell重用

    少数几个cell可不重用 NSString *CellIdentifier = [NSString stringWithFormat:@"MyCellID_%d",indexPat ...

  6. xss标签和属性爆破

    当网站过滤了大部分的HTML标签和属性,我们就尝试爆破一下,看哪些标签和属性没有没过滤. 爆破的步骤: 1. 首先在测试点输入我们正常的exp,并抓包发送到Intruder模块. 2. 将exp改为 ...

  7. 【BZOJ2337】XOR和路径(高斯消元)

    题目链接 大意 给出\(N\)个点,\(M\)条边的一张图,其中每条边都有一个非负整数边权. 一个人从1号点出发,在与该点相连的边中等概率的选择一条游走,直到走到\(N\)号点. 问:将这条路径上的边 ...

  8. WebGPU 中消失的 FBO 和 RBO

    目录 1 WebGL 中的 FBO 与 RBO 1.1 帧缓冲对象(FramebufferObject) 1.2 颜色附件与深度模板附件的真正载体 1.3 FBO/RBO/WebGLTexture 相 ...

  9. 带你十天轻松搞定 Go 微服务系列(九、链路追踪)

    序言 我们通过一个系列文章跟大家详细展示一个 go-zero 微服务示例,整个系列分十篇文章,目录结构如下: 环境搭建 服务拆分 用户服务 产品服务 订单服务 支付服务 RPC 服务 Auth 验证 ...

  10. 如何写出优雅又地道的Python代码?【转载】

    在Python社区文化的浇灌下,演化出了一种独特的代码风格,去指导如何正确地使用Python,这就是常说的pythonic.一般说地道(idiomatic)的python代码,就是指这份代码很pyth ...