Laravel上传产品图片Uploading img
这节我们讲Laravel产品图片上传,有很多方式可以实现,这里我们用intervention/image插件来进行。首先安装intervention/image插件,在命令行输入
composer require intervention/image
安装完成后要修改config/app.php文件
//在$providers中添加一行
Intervention\Image\ImageServiceProvider::class,
//在$aliases中添加一行
'Image' => Intervention\Image\Facades\Image::class,
发布配置,在命令行中输入
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravel5"
这时弹出Copied File [/vendor/intervention/image/src/config/config.php] To [/config/image.php]提示已经复制配置文件到config/image.php,你可以在这里进行设置。
修改controller配置,文件在/app/Http/Controllers/ItemController.php,
if($request->hasFile('img'))
{
$image = $request->file('img');
$filename = time() . '.' . $image->getClientOriginalExtension();
$location = public_path('img/' . $filename);
Image::make($image)->save($location);
$item->img = url('img/' . $filename);
}
修改create.blade.php文件,表格form要加一个参数enctype="multipart/form-data",选择图片改为<input type="file" name="img" >
@extends('layouts.app')
@if ($errors->any())
<div class="alert alert-danger">
<strong>Errors:</strong>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
@section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="card card-default">
<div class="card-header">Create New Item</div>
<div class="card-body">
<form method="POST" action="/items" aria-label="Register" enctype="multipart/form-data">
@csrf
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">Name</label>
<div class="col-md-6">
<input id="name" type="text" name="name" value="" required="required" autofocus="autofocus" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="email" class="col-md-4 col-form-label text-md-right">Price</label>
<div class="col-md-6">
<input id="email" type="text" name="price" value="" required="required" class="form-control">
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">Img</label>
<div class="col-md-6">
<input type="file" name="img" >
</div>
</div>
<div class="form-group row">
<label for="password-confirm" class="col-md-4 col-form-label text-md-right">Description</label>
<div class="col-md-6">
<input id="password-confirm" type="text" name="description" required="required" class="form-control">
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">Save</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@endsection
Laravel上传产品图片Uploading img的更多相关文章
- 基于spring-boot的web应用,ckeditor上传文件图片文件
说来惭愧,这个应用调试,折腾了我一整天,google了很多帖子,才算整明白,今天在这里做个记录和分享吧,也作为自己后续的参考! 第一步,ckeditor(本博文论及的ckeditor版本4.5.6)的 ...
- laravel上传文件到七牛云存储
背景 最近在用PHP和laravel框架做一个图片网站,需要将图片存贮到云端,搜索下了对比了下功能,发现七牛云存储不错(主要小流量免费),便选择使用七牛作为图片存储空间. 要实现的功能很简单,选择本地 ...
- Laravel上传文件(单文件,多文件)
为了方便,先修改一个配置文件,再laravel框架中config配置中找到 filesystems.php 文件 修改代码如下 'local' => [ 'driver' => 'loc ...
- PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件
PHP 多图上传,图片批量上传插件,webuploader.js,百度文件上传插件(案例教程) WebUploader作用:http://fex.baidu.com/webuploader/gett ...
- thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印
今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...
- ASP.NET、JAVA跨服务器远程上传文件(图片)的相关解决方案整合
一.图片提交例: A端--提交图片 protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string u ...
- 如何预览将要上传的图片-使用H5的FileAPI
这篇将要说的东西已经不新鲜了. 参考资料: Reading files in JavaScript using the File APIs (鉴于作者在美国, 我姑且认为作者母语是英语, 当然链接中有 ...
- js上传压缩图片
原文链接:http://blog.csdn.net/iefreer/article/details/53039848 手机用户拍的照片通常会有2M以上,这对服务器带宽产生较大压力. 因此在某些应用下( ...
- php 实现接收客户端上传的图片
今天,遇到一个服务端接收客户端上传图片的需求,经过学习.我写了个简单的demo 以备下次学习. 首先服务器接收的发送图片的请求一定要是post请求,而且请求一定要加上 enctype="mu ...
随机推荐
- Linux Platform驱动模型(三) _platform+cdev
平台总线是一种实现设备信息与驱动方法相分离的方法,利用这种方法,我们可以写出一个更像样一点的字符设备驱动,即使用cdev作为接口,平台总线作为分离方式: xjkeydrv_init():模块加载函数 ...
- Unity 给Mono脚本添加Try Catch工具
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Run ...
- 关于linux Centos 7一个网卡配置多个IP的方法
有时我们在工作中,会遇到一个网卡配置多个ip的情况,尤其是在linux服务器方面的应用教多 于是笔者将其配置过程整理如下,希望能帮到遇到同样问题的朋友,这里以vmware虚拟机下的Centos 7为例 ...
- 关于web标准的一些想法
关于web标准的一些想法 页面结构,表现,行为的关系.应该是各自分离又紧密联系的关系.从代码上分离出来.各自完成各自的功能,方便以后维护.紧密联系是指他们是相互依赖的.结构是核心,虽然从理论上讲不管什 ...
- onems设备管理系统(TR-069和OMA)
onems设备管理系统(TR-069和OMA) 沃克斯科技OneMS设备管理套件是一个全面的为服务提供商和企业提供自动配置和远程管理功能的设备管理解决方案.它利用现有的网络基础设施来自动化订购,预配置 ...
- Solr7.4.0的API(Solrj)操作及项目中的使用
一.SolrJ的概念 solr单机版服务搭建:https://www.cnblogs.com/frankdeng/p/9615253.html solr集群版服务搭建:https://www.cnbl ...
- Slapper帮助Dapper实现一对多
Dapper的Query的方法提供了多个泛型重载可以帮助我们实现导航属性的查询 1对1 public class Employees4List { public int Id { get; set; ...
- Flask web开发之路一
之前学过一段时间的flask,感觉还是挺好用的,自己的专利挖掘项目也想这个web框架来搭建,于是重新开始基础学习 环境:win10,python3.6,pycharm2017,虚拟环境virtuale ...
- Cross-origin plugin content from must have a visible size larger than 400 x 300 pixels, or it will be blocked. Invisible content is always blocked.
Cross-origin plugin content from must have a visible size larger than 400 x 300 pixels, or it will ...
- 泡泡一分钟:Towards real-time unsupervised monocular depth estimation on CPU
Towards real-time unsupervised monocular depth estimation on CPU Matteo Poggi , Filippo Aleotti , Fa ...