*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->
#在laravel环境下将图片存入MongoDB数据库#

此处使用的是base64方法;

  先获取到上传的图片,再获取其详细信息,代码如下:

    $Info = getimagesize($file);
$Info_data = fread(fopen($file,'r'), filesize($file));
$base = base64_encode($Info_data);
  • $file为获取的图片文件;
  • getimagesize()函数用来获取图片文件信息;
  • fread(,)用来读取文件
    • 第一个参数是 必需 规定要读取打开的文件。

      • fopen($file,'r') 只读,并将文件指针指向开始位置。
    • 第二个参数是 必须 规定要读取的最大字节数。
      • filesize($file) 返回指定文件的大小。
  • base64_encode() 编译 成 base64 格式;

    存入MongoDB数据库的操作:
    
        $photo = new PhotoModel();
    $photo->name = $name;
    $photo->photo_base64 = $base;
    $photo->save();

    Emmm~ 这块不明白的话看laravel下的 ☞ MongoDB扩展

    然后就是从MongoDB数据库中拿出并解析成图片,代码如下:
    
        //取出
    $photo_Info = PhotoModel::where('name','=',$name)->take(1)->get(['photo_base64']);
    //转换并输出图片;
    $img = base64_decode($photo_Info[0]['photo_base64']);
    $img_analysis = file_put_contents('./test.jpg', $img);
  • base64_decode() 解析 还原成字符串

  • fileputcontents() 将一个字符串写入到文件中

    • 第一个是存储的目录 例如现在指的是当前目录下,生成一个test.jpg文件
    • 图片信息

      接下来就是源码:

` <?php 
  namespace App\Http\Controllers;
  use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use App\Models\PhotoModel;
/**
* 该控制器用来接收并存储图片至本地;
*/
class GetPhotoController extends Controller
{
//获取图片;
public function GetPhoto(Request $Request)
{
if ($Request->hasFile('photo') && $Request->file('photo')->isValid()) {
//获取图片值;
$file = $Request->file('photo');
//获取输入的name值;
$name = $Request->input('name');
$path = $file->path(); //获取当前文件的扩展名;
$extension = $file->extension();
//设置支持的文件格式;
// $allowed_extensions = ['png','jpg','gif']; // //判断图片文件格式是否支持;
// if ($extension && !in_array($extension, $allowed_extensions))
// {
// return ['error' => '上传的图片格式不支持(支持png,jpg,gif等)'];
// } //设置时间名为文件名
$time = time();
$time = date("y-m-d",$time).'-'.date("H-i-s",$time).$time;
$path = $file->storeAs('images',$time.'.'.$extension); //存入MongoDB数据库 //一、转成base64
$Info = getimagesize($file);
$Info_data = fread(fopen($file,'r'), filesize($file));
$base = base64_encode($Info_data); //二、存入数据库;
$photo = new PhotoModel();
$photo->name = $name;
$photo->photo_base64 = $base;
$photo->save(); //三、取出
$photo_Info = PhotoModel::where('name','=',$name)->take(1)->get(['photo_base64']);
//四、转换并输出图片;
$img = base64_decode($photo_Info[0]['photo_base64']);
$img_analysis = file_put_contents('./test.jpg', $img);
return $base;
}else{
return "文件格式不正确";
}
}}`

最新文章

  1. Andriod Studio adb.exe,start-server&#39; failed -- run manually if necessary 解决
  2. shell命令rm删除非空文件夹
  3. 注解:【有连接表的】Hibernate单向1-&gt;N关联
  4. CRB and String
  5. PostgreSQL数据库服务端监听设置及客户端连接方法教程
  6. 51nod1119 机器人走方格 V2
  7. 普通的101键盘在Mac上的键位对应
  8. 倒计时 NAN 问题
  9. javascript原型链继承
  10. 通过自定义window来实现提示框效果
  11. Delphi -- 创建 桌面、发送到...、快速启动栏、开始菜单、程序菜单、右键菜 单
  12. 从壹开始前后端分离 [ vue + .netcore 补充教程 ] 二八║ Nuxt 基础:面向源码研究Nuxt.js
  13. layUI弹出框提示
  14. mac上遇到的坑
  15. python2中urllib2模块带cookies使用方法
  16. react 简单的用函数调出ui显示
  17. Xshell远程连接 与 Xftp文件传输
  18. 研究CondItem
  19. springcloud 入门 6 (断路器hystrix)
  20. 【Python】HackBack(获取暴力破解服务器密码的IP来源)

热门文章

  1. 嵌入式linux系统的构建
  2. maven的安装与配置使用
  3. 根据展示文字自适应 cell 高度,实现点击cell的伸缩扩展
  4. virsh 常用操作
  5. python自动化--语言基础1--数据类型及类型转换
  6. $.ajax的一些坑啊
  7. js中的写出想jquery中的函数一样调用
  8. yii2 查询构建器
  9. 快速入门vue-cli配置
  10. Hibernate5环境搭建