فهرست منبع

文件上传阿里云

任敬轩 4 سال پیش
والد
کامیت
3098c32b3d

+ 25 - 10
app/Http/Controllers/Account/ProfileController.php

@@ -66,18 +66,30 @@ class ProfileController extends Controller
         return view('theme::profile.base')->with('data',$data);
     }
 
+    function upload_image($path, $file, $drive = 'oss')
+    {
+        $disk = Storage::disk($drive);
+        //将图片上传到OSS中,并返回图片路径信息 值如:avatar/WsH9mBklpAQUBQB4mL.jpeg
+        $path = $disk->put($path, $file);
+        //由于图片不在本地,所以我们应该获取图片的完整路径,
+        //值如:https://test.oss-cn-hongkong.aliyuncs.com/avatar/8GdIcz1NaCZ.jpeg
+        return $disk->url($path);
+    }
+
     /**
      * 修改用户头像
      * @param Request $request
      */
     public function postAvatar(Request $request)
     {
+
+
+
         $validateRules = [
             'user_avatar' => 'required|image',
         ];
 
         if($request->hasFile('user_avatar')){
-
             $this->validate($request,$validateRules);
             $user_id = $request->user()->id;
             $file = $request->file('user_avatar');
@@ -86,18 +98,21 @@ class ProfileController extends Controller
             $extArray = array('png', 'gif', 'jpeg', 'jpg');
 
             if(in_array($extension, $extArray)){
-	            if($extension != 'jpg'){
-                    Image::make(File::get($file))->save(storage_path('app/'.User::getAvatarPath($user_id,'origin')));
-                    Image::make(File::get($file))->save(app('path.public').'/static/uploads/user_origin_'.$user_id.'.jpg');
-                }else{
-                    Storage::disk('local')->put($avatarDir.'/'.User::getAvatarFileName($user_id,'origin').'.'.$extension,File::get($file));
-                }
+//	            if($extension != 'jpg'){
+//                    Image::make(File::get($file))->save(storage_path('app/'.User::getAvatarPath($user_id,'origin')));
+//                    Image::make(File::get($file))->save(app('path.public').'/static/uploads/user_origin_'.$user_id.'.jpg');
+                    $path = 'avatar/' . date("Ym/d", time());
+                    $data['qrcode'] = $this->upload_image($path, $request->user_avatar);
+                    DB::table('users')->where('id','=',$user_id)->update($data);
+//                }else{
+//                    Storage::disk('local')->put($avatarDir.'/'.User::getAvatarFileName($user_id,'origin').'.'.$extension,File::get($file));
+//                }
             }else{
                 return response('error');
             }
 
             return response()->json(array(
-                'status' => 1,
+                'url' => $data['qrcode'],
                 'msg' => '头像上传成功'
             ));
         }
@@ -116,7 +131,8 @@ class ProfileController extends Controller
 //            Image::make(storage_path('app/'.User::getAvatarPath($user_id,'origin')))->crop($width,$height,$x,$y)->resize(128,128)->save(storage_path('app/'.User::getAvatarPath($user_id,'big')));
 //            Image::make(storage_path('app/'.User::getAvatarPath($user_id,'origin')))->crop($width,$height,$x,$y)->resize(64,64)->save(storage_path('app/'.User::getAvatarPath($user_id,'middle')));
 //            Image::make(storage_path('app/'.User::getAvatarPath($user_id,'origin')))->crop($width,$height,$x,$y)->resize(24,24)->save(storage_path('app/'.User::getAvatarPath($user_id,'small')));
-
+//            $path = 'avatar/' . date("Ym/d", time());
+//            $data['qrcode'] = $this->upload_image($path, $request->user_avatar);
             File::delete(app('path.public').'/static/uploads/user_big_'.$user_id.'.jpg');
             File::delete(app('path.public').'/static/uploads/user_middle_'.$user_id.'.jpg');
             File::delete(app('path.public').'/static/uploads/user_small_'.$user_id.'.jpg');
@@ -263,5 +279,4 @@ class ProfileController extends Controller
 
     }
 
-
 }

+ 13 - 8
app/Http/Controllers/Blog/ArticleController.php

@@ -101,10 +101,8 @@ class ArticleController extends Controller
             ];
             $this->validate($request,$validateRules);
             $file = $request->file('logo');
-            $extension = $file->getClientOriginalExtension();
-            $filePath = 'articles/'.gmdate("Y")."/".gmdate("m")."/".uniqid(str_random(8)).'.'.$extension;
-            Storage::disk('local')->put($filePath,File::get($file));
-            $data['logo'] = str_replace("/","-",$filePath);
+            $path = 'avatar/' . date("Ym/d", time());
+            $data['logo'] = $this->upload_image($path, $file);
         }
 
 
@@ -144,6 +142,15 @@ class ArticleController extends Controller
 
     }
 
+    function upload_image($path, $file, $drive = 'oss')
+    {
+        $disk = Storage::disk($drive);
+        //将图片上传到OSS中,并返回图片路径信息 值如:avatar/WsH9mBklpAQUBQB4mL.jpeg
+        $path = $disk->put($path, $file);
+        //由于图片不在本地,所以我们应该获取图片的完整路径,
+        //值如:https://test.oss-cn-hongkong.aliyuncs.com/avatar/8GdIcz1NaCZ.jpeg
+        return $disk->url($path);
+    }
     /**
      * Display the specified resource.
      *
@@ -248,10 +255,8 @@ class ArticleController extends Controller
             ];
             $this->validate($request,$validateRules);
             $file = $request->file('logo');
-            $extension = $file->getClientOriginalExtension();
-            $filePath = 'articles/'.gmdate("Y")."/".gmdate("m")."/".uniqid(str_random(8)).'.'.$extension;
-            Storage::disk('local')->put($filePath,File::get($file));
-            $article->logo = str_replace("/","-",$filePath);
+            $path = 'avatar/' . date("Ym/d", time());
+            $article->logo = $this->upload_image($path, $file);
         }
 
 

+ 0 - 1
app/Http/Controllers/IndexController.php

@@ -85,7 +85,6 @@ class IndexController extends Controller
         $hotExperts = Cache::remember('index_hot_experts',Setting()->get('website_cache_time',1),function(){
             return  Authentication::hottest(8);
         });
-
         $hotUsers = Cache::remember('index_hot_users',30,function() {
             return  UserData::hottest(20);
         });

+ 1 - 1
app/Models/UserData.php

@@ -65,7 +65,7 @@ class UserData extends Model
             ->orderBy('user_data.answers', 'DESC')
             ->orderBy('user_data.articles', 'DESC')
             ->orderBy('users.updated_at', 'DESC')
-            ->select('users.id', 'users.name', 'users.title', 'user_data.coins', 'user_data.credits',
+            ->select('users.id', 'users.name', 'users.title','users.qrcode', 'user_data.coins', 'user_data.credits',
                 'user_data.followers', 'user_data.supports', 'user_data.answers', 'user_data.articles',
                 'user_data.authentication_status')
             ->take($size)->get();

+ 4 - 1
composer.json

@@ -10,6 +10,8 @@
         "fideloper/proxy": "^4.0",
         "germey/geetest": "^3.0",
         "intervention/image": "^2.4",
+        "jacobcyl/ali-oss-storage": "^2.1",
+        "johnlui/aliyun-oss": "~2.0",
         "laravel/framework": "5.6.*",
         "laravel/tinker": "^1.0",
         "laravelium/sitemap": "2.8.*",
@@ -33,7 +35,8 @@
     "autoload": {
         "classmap": [
             "database/seeds",
-            "database/factories"
+            "database/factories",
+            "app/services"
         ],
         "psr-4": {
             "App\\": "app/"

+ 163 - 7
composer.lock

@@ -1,12 +1,59 @@
 {
     "_readme": [
         "This file locks the dependencies of your project to a known state",
-        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
+        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "1e384d623e31a965b1b464abfbb3ff95",
+    "content-hash": "b0185e6340bf042515e33369b3875eae",
     "packages": [
         {
+            "name": "aliyuncs/oss-sdk-php",
+            "version": "v2.4.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/aliyun/aliyun-oss-php-sdk.git",
+                "reference": "492866331b7bafaac09506cf42f351b7e9e63766"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/aliyun/aliyun-oss-php-sdk/zipball/492866331b7bafaac09506cf42f351b7e9e63766",
+                "reference": "492866331b7bafaac09506cf42f351b7e9e63766",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.3"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "~4.0",
+                "satooshi/php-coveralls": "~1.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "OSS\\": "src/OSS"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Aliyuncs",
+                    "homepage": "http://www.aliyun.com"
+                }
+            ],
+            "description": "Aliyun OSS SDK for PHP",
+            "homepage": "http://www.aliyun.com/product/oss/",
+            "time": "2020-09-29T06:23:57+00:00"
+        },
+        {
             "name": "bacon/bacon-qr-code",
             "version": "1.0.3",
             "source": {
@@ -1113,6 +1160,63 @@
             "time": "2019-06-24T14:06:31+00:00"
         },
         {
+            "name": "jacobcyl/ali-oss-storage",
+            "version": "2.1.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/jacobcyl/Aliyun-oss-storage.git",
+                "reference": "c0cb9ba1d3faf22a1e04a03602aac90a187b5959"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/jacobcyl/Aliyun-oss-storage/zipball/c0cb9ba1d3faf22a1e04a03602aac90a187b5959",
+                "reference": "c0cb9ba1d3faf22a1e04a03602aac90a187b5959",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "aliyuncs/oss-sdk-php": "~2.0"
+            },
+            "type": "library",
+            "extra": {
+                "laravel": {
+                    "providers": [
+                        "Jacobcyl\\AliOSS\\AliOssServiceProvider"
+                    ]
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Jacobcyl\\AliOSS\\": "src/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "jacobcyl",
+                    "email": "cyl.jacob@gmail.com"
+                }
+            ],
+            "description": "aliyun oss filesystem storage for laravel 5+",
+            "homepage": "http://jacobcyl.github.io/Aliyun-oss-storage/",
+            "keywords": [
+                "aliyun",
+                "filesystems",
+                "laravel",
+                "oss",
+                "storage"
+            ],
+            "time": "2018-04-02T03:44:01+00:00"
+        },
+        {
             "name": "jakub-onderka/php-console-color",
             "version": "v0.2",
             "source": {
@@ -1158,6 +1262,7 @@
                     "email": "jakub.onderka@gmail.com"
                 }
             ],
+            "abandoned": "php-parallel-lint/php-console-color",
             "time": "2018-09-29T17:23:10+00:00"
         },
         {
@@ -1210,9 +1315,58 @@
                 }
             ],
             "description": "Highlight PHP code in terminal",
+            "abandoned": "php-parallel-lint/php-console-highlighter",
             "time": "2018-09-29T18:48:56+00:00"
         },
         {
+            "name": "johnlui/aliyun-oss",
+            "version": "v2.2.1",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/johnlui/AliyunOSS.git",
+                "reference": "f10fdec4775e22a8295366981e1daf48c62ce5d3"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/johnlui/AliyunOSS/zipball/f10fdec4775e22a8295366981e1daf48c62ce5d3",
+                "reference": "f10fdec4775e22a8295366981e1daf48c62ce5d3",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "php": ">=5.4.0"
+            },
+            "type": "library",
+            "autoload": {
+                "files": [
+                    "src/AliyunOSS.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "John Lui",
+                    "email": "wenhanlv@gmail.com"
+                }
+            ],
+            "description": "阿里云 OSS 官方 SDK 的 Composer 封装,支持任何 PHP 项目,包括 Laravel、Symfony、TinyLara 等等。",
+            "homepage": "https://github.com/johnlui/AliyunOSS",
+            "keywords": [
+                "AliyunOSS",
+                "aliyun",
+                "oss"
+            ],
+            "time": "2017-04-06T06:48:21+00:00"
+        },
+        {
             "name": "kylekatarnls/update-helper",
             "version": "1.2.0",
             "source": {
@@ -1551,12 +1705,12 @@
             "version": "v2.8.3",
             "source": {
                 "type": "git",
-                "url": "https://gitlab.com/Laravelium/Sitemap.git",
+                "url": "https://github.com/Laravelium/laravel-sitemap.git",
                 "reference": "91a26679cc8d6ce59474d678bd23bee4d8471e0e"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://gitlab.com/api/v4/projects/Laravelium%2FSitemap/repository/archive.zip?sha=91a26679cc8d6ce59474d678bd23bee4d8471e0e",
+                "url": "https://api.github.com/repos/Laravelium/laravel-sitemap/zipball/91a26679cc8d6ce59474d678bd23bee4d8471e0e",
                 "reference": "91a26679cc8d6ce59474d678bd23bee4d8471e0e",
                 "shasum": "",
                 "mirrors": [
@@ -2281,12 +2435,12 @@
             "version": "v1.1.1",
             "source": {
                 "type": "git",
-                "url": "https://github.com/nrk/predis.git",
+                "url": "https://github.com/predis/predis.git",
                 "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
+                "url": "https://api.github.com/repos/predis/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
                 "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
                 "shasum": "",
                 "mirrors": [
@@ -5756,6 +5910,7 @@
             "keywords": [
                 "tokenizer"
             ],
+            "abandoned": true,
             "time": "2019-09-17T06:23:10+00:00"
         },
         {
@@ -6591,5 +6746,6 @@
     "platform": {
         "php": "^7.1.3"
     },
-    "platform-dev": []
+    "platform-dev": [],
+    "plugin-api-version": "1.1.0"
 }

+ 1 - 1
config/app.php

@@ -170,7 +170,7 @@ return [
         App\Providers\EventServiceProvider::class,
         App\Providers\RouteServiceProvider::class,
         App\Providers\ThemeServiceProvider::class,
-
+        Jacobcyl\AliOSS\AliOssServiceProvider::class,
 
     ],
 

+ 13 - 0
config/filesystems.php

@@ -64,6 +64,19 @@ return [
             'url' => env('AWS_URL'),
         ],
 
+        'oss' => [
+            'driver'        => 'oss',
+            'access_id'     => 'LTAICf62eG5csLjc',
+            'access_key'    => 'ZkWb0KW2sunAGQnt0k3SDtYrOb7GeQ',
+            'bucket'        => 'jiewei-php-files',
+            'endpoint'      => 'oss-cn-qingdao.aliyuncs.com', // OSS 外网节点或自定义外部域名
+            //'endpoint_internal' => '<internal endpoint [OSS内网节点] 如:oss-cn-shenzhen-internal.aliyuncs.com>', // v2.0.4 新增配置属性,如果为空,则默认使用 endpoint 配置(由于内网上传有点小问题未解决,请大家暂时不要使用内网节点上传,正在与阿里技术沟通中)
+            //   'cdnDomain'     => '<CDN domain, cdn域名>', // 如果isCName为true, getUrl会判断cdnDomain是否设定来决定返回的url,如果cdnDomain未设置,则使用endpoint来生成url,否则使用cdn
+            'ssl'           => false, // true to use 'https://' and false to use 'http://'. default is false,
+            'isCName'       => false, // 是否使用自定义域名,true: 则Storage.url()会使用自定义的cdn或域名生成文件url, false: 则使用外部节点生成url
+            'debug'         => false,
+        ],
+
     ],
 
 ];

+ 5 - 5
resources/views/themes/default/article/create.blade.php

@@ -25,11 +25,11 @@
                     <input id="title" type="text" name="title"  class="form-control input-lg" placeholder="" value="{{ old('title',$formData['subject']) }}" />
                     @if($errors->has('title')) <p class="help-block">{{ $errors->first('title') }}</p> @endif
                 </div>
-{{--                <div class="form-group @if($errors->has('logo')) has-error @endif">--}}
-{{--                    <label>文章封面</label>--}}
-{{--                    <input type="file" name="logo"/>--}}
-{{--                    @if($errors->has('logo')) <p class="help-block">{{ $errors->first('logo') }}</p> @else <p class="help-block">建议尺寸200*120</p> @endif--}}
-{{--                </div>--}}
+                <div class="form-group @if($errors->has('logo')) has-error @endif">
+                    <label>文章封面</label>
+                    <input type="file" name="logo"/>
+                    @if($errors->has('logo')) <p class="help-block">{{ $errors->first('logo') }}</p> @else <p class="help-block">建议尺寸200*120</p> @endif
+                </div>
                 <div class="form-group  @if($errors->has('content')) has-error @endif">
                     <label for="article_editor">文章正文:</label>
                     <div id="article_editor">{!! old('content',$formData['content']) !!}</div>

+ 10 - 10
resources/views/themes/default/article/edit.blade.php

@@ -26,16 +26,16 @@
                     @if($errors->has('title')) <p class="help-block">{{ $errors->first('title') }}</p> @endif
                 </div>
 
-{{--                <div class="form-group @if($errors->has('logo')) has-error @endif">--}}
-{{--                    <label>文章封面</label>--}}
-{{--                    <input type="file" name="logo" />--}}
-{{--                    @if($article->logo)--}}
-{{--                        <div style="margin-top: 10px;">--}}
-{{--                            <img src="{{ route('website.image.show',['image_name'=>$article->logo]) }}" />--}}
-{{--                        </div>--}}
-{{--                    @endif--}}
-{{--                    @if($errors->has('logo')) <p class="help-block">{{ $errors->first('logo') }}</p> @endif--}}
-{{--                </div>--}}
+                <div class="form-group @if($errors->has('logo')) has-error @endif">
+                    <label>文章封面</label>
+                    <input type="file" name="logo" />
+                    @if($article->logo)
+                        <div style="margin-top: 10px;">
+                            <img src="{{ $article->logo }}" style="height:100px;"/>
+                        </div>
+                    @endif
+                    @if($errors->has('logo')) <p class="help-block">{{ $errors->first('logo') }}</p> @endif
+                </div>
 
 
                 <div class="form-group  @if($errors->has('content')) has-error @endif">

+ 2 - 2
resources/views/themes/default/article/show.blade.php

@@ -104,7 +104,7 @@
         <div class="col-xs-12 col-md-3 side">
             <div class="widget-user">
                 <div class="media">
-                    <a class="pull-left" href="{{ route('auth.space.index',['user_id'=>$article->user_id]) }}"><img class="media-object avatar-64" src="/static/images/default_avatar.jpg" alt="{{ $article->user->name }}"></a>
+                    <a class="pull-left" href="{{ route('auth.space.index',['user_id'=>$article->user_id]) }}"><img class="media-object avatar-64" src="{{ $article->user->qrcode }}" alt="{{ $article->user->name }}"></a>
                     <div class="media-body ">
                         <a href="{{ route('auth.space.index',['user_id'=>$article->user_id]) }}" class="media-heading">{{ $article->user->name }}</a>
                         @if($article->user->title)
@@ -122,7 +122,7 @@
                 <ol class="widget-top10">
                     @foreach($topUsers as $index => $topUser)
                         <li class="text-muted">
-                            <img class="avatar-32" src="/static/images/default_avatar.jpg">
+                            <img class="avatar-32" src="{{ $topUser['qrcode'] }}">
                             <a href="{{ route('auth.space.index',['user_id'=>$topUser['id']]) }}" class="ellipsis">{{ $topUser['name'] }}</a>
                             <span class="text-muted pull-right">{{ $topUser['articles'] }} 文章</span>
                         </li>

+ 1 - 1
resources/views/themes/default/home/ask.blade.php

@@ -112,7 +112,7 @@
                 <ol class="widget-top10">
                     @foreach($hotUsers as $index => $hotUser)
                         <li class="text-muted">
-                            <img class="avatar-32" src="/static/images/default_avatar.jpg">
+                            <img class="avatar-32" src="{{ $hotUser['qrcode'] }}">
                             <a href="{{ route('auth.space.index',['user_id'=>$hotUser['id']]) }}" class="ellipsis">{{ $hotUser['name'] }}</a>
                             <span class="text-muted pull-right">{{ $hotUser['credits'] }} 经验</span>
                         </li>

+ 3 - 3
resources/views/themes/default/home/blog.blade.php

@@ -35,7 +35,7 @@
                 <section class="stream-list-item clearfix">
                     @if( $article->logo )
                     <div class="blog-rank hidden-xs">
-                        <a href="{{ route('blog.article.detail',['id'=>$article->id]) }}" target="_blank"><img style="width: 200px;height:120px;" src="{{ route('website.image.show',['image_name'=>$article->logo]) }}"></a>
+                        <a href="{{ route('blog.article.detail',['id'=>$article->id]) }}" target="_blank"><img style="width: 200px;height:120px;" src="{{ $article->logo }}"></a>
                     </div>
                     @endif
                     <div class="summary">
@@ -50,7 +50,7 @@
                             </li>
                             <li>
                                 <a href="{{ route('auth.space.index',['user_id'=>$article->user_id]) }}" target="_blank">
-                                    <img class="avatar-20 mr-10 hidden-xs" src="/static/images/default_avatar.jpg" alt="{{ $article->user->name }}"> {{ $article->user->name }}
+                                    <img class="avatar-20 mr-10 hidden-xs" src="{{ $article->user->qrcode }}" alt="{{ $article->user->name }}"> {{ $article->user->name }}
                                 </a>
                             </li>
                             <li>发布于 {{ timestamp_format($article->created_at) }}</li>
@@ -92,7 +92,7 @@
                     @foreach($hotUsers as $hotUser)
                     <li class="media  widget-user-item ">
                         <a href="{{ route('auth.space.index',['user_id'=>$hotUser['id']]) }}" class="user-card pull-left" target="_blank">
-                            <img class="avatar-50"  src="/static/images/default_avatar.jpg" alt="{{ $hotUser->name }}"></a>
+                            <img class="avatar-50"  src="{{ $hotUser->qrcode }}" alt="{{ $hotUser->name }}"></a>
                         </a>
                         <div class="media-object">
                             <strong><a href="{{ route('auth.space.index',['user_id'=>$hotUser['id']]) }}">{{ $hotUser['name'] }}</a></strong>

+ 1 - 1
resources/views/themes/default/home/index.blade.php

@@ -86,7 +86,7 @@
                         @foreach($hotExperts as $expert)
                             <section class="col-sm-6 col-md-3">
                                 <div class="thumbnail">
-                                    <a href="{{ route('auth.space.index',['user_id'=>$expert->user_id]) }}" target="_blank"><img class="avatar-128" src="/static/images/default_avatar.jpg" alt="{{ $expert->real_name }}"></a>
+                                    <a href="{{ route('auth.space.index',['user_id'=>$expert->user_id]) }}" target="_blank"><img class="avatar-128" src="{{ $expert->title }}" alt="{{ $expert->real_name }}"></a>
                                     <div class="caption">
                                         <h4 class="text-center"><a href="{{ route('auth.space.index',['user_id'=>$expert->user_id]) }}" title="{{ $expert->real_name }}">{{ str_limit($expert->real_name,10,'') }}</a></h4>
                                         <p class="text-muted text-center" title="{{ $expert->title }}">{{ str_limit($expert->title,16,'') }}&nbsp;</p>

+ 1 - 1
resources/views/themes/default/layout/public.blade.php

@@ -108,7 +108,7 @@
                             <li><a href="{{ route('auth.message.index') }}" class="active" id="unread_messages"><i class="fa fa-envelope-o fa-lg"></i></a></li>
                             <li class="dropdown user-avatar">
                                 <a href="{{ route('auth.profile.base') }}" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
-                                    <img class="avatar-32 mr-5" alt="{{ Auth()->user()->name }}" src="{{ Auth()->user()->qrcode }}" >
+                                    <img class="avatar-32 mr-5" alt="{{ Auth()->user()->name }}" src="{{ Auth()->user()->qrcode }}" id="top_img">
                                     <span>{{ Auth()->user()->name }}</span>
                                 </a>
                                 <ul class="dropdown-menu" role="menu">

+ 33 - 9
resources/views/themes/default/profile/base.blade.php

@@ -12,7 +12,6 @@
     <div class="row">
         <!--左侧菜单-->
         @include('theme::layout.profile_menu')
-
         <div id="main" class="settings col-md-10 form-horizontal main">
             <h2 class="h3 post-title">个人资料</h2>
             <div class="row mt-30">
@@ -21,7 +20,8 @@
 {{--                    {{ Auth()->user()->qrcode }}--}}
                     <div class="wu-example mt-10">
                         <div class="change-avatar">
-                            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#avatar_modal">修改头像</button>
+                            <button type="button" class="btn btn-primary" data-toggle="modal" onclick="upload.click()">修改头像</button>
+                            <input type="file" name="upload" id="upload" style="display: none;" />
                             <p class="text-muted mt-10">从电脑中选择图片上传, 图像大小不要超过 2 MB</p>
                             <div class="modal fade" id="avatar_modal" tabindex="-1" role="dialog" aria-labelledby="avatar_model_label">
                                 <div class="modal-dialog">
@@ -34,13 +34,13 @@
                                             <div class="row">
                                                 <div class="col-xs-6 text-center">
                                                     <div id="avatar_origin" class="avatar-container">
-                                                        <img class="avatar-origin" src="{{ Auth()->user()->qrcode }}">
+                                                        <img class="avatar-origin" src="http://jiewei-php-files.oss-cn-qingdao.aliyuncs.com/avatar/202010/29/kSra9MSHMCH1xKyZ8mEpHW2luwXJsrtuSMTsE2OC.png">
                                                     </div>
                                                     <!--用来存放文件信息-->
-                                                    <div id="uploader">
-                                                        <div id="fileList" class="uploader-list"></div>
-                                                        <div id="filePicker" class="picker-container">选择图片</div>
-                                                    </div>
+{{--                                                    <div id="uploader">--}}
+{{--                                                        <div id="fileList" class="uploader-list"></div>--}}
+{{--                                                        <div id="filePicker" class="picker-container">选择图片</div>--}}
+{{--                                                    </div>--}}
                                                 </div>
                                                 <div class="col-xs-6 text-center mt-5">
                                                     <div class="preview-container img-preview">
@@ -148,6 +148,30 @@
     <script src="{{ asset('/static/js/cropper/cropper.min.js') }}"></script>
 
     <script type="text/javascript">
+        upload.onchange = function(){
+            var upload = document.getElementById('upload');
+            var formData = new FormData();
+            formData.append('user_avatar', document.getElementById('upload').files[0]);
+            {{--$.post("{{ route('auth.profile.avatar') }}", {qwer: upload.value}, function(data){--}}
+            {{--    console.log(data);--}}
+            {{--});--}}
+            $.ajax({
+                url:"{{ route('auth.profile.avatar') }}",
+                type:"post",
+                data: formData,
+                contentType: false,
+                processData: false,
+                success: function(data) {
+                    console.log(data);
+                    document.getElementById('user_avatar_image').src = data.url;
+                    document.getElementById('top_img').src = data.url;
+                },
+                error:function(data) {
+                    alert("上传失败")
+                }
+            });
+        }
+        // img.setAttribute('crossOrigin', 'anonymous');
         $(function(){
             /*生日日历*/
             $("#birthday").datepicker({
@@ -262,8 +286,8 @@
             $('#avatar_btn').click(function(){
                 var cropper = avatar_origin.cropper('getData');
                 $.post("{{ route('auth.profile.avatar') }}", {_token: '{{ csrf_token() }}', x: cropper.x, y: cropper.y, width: cropper.width, height: cropper.height}, function(data){
-                    console.log(data);
-                    if (data.status === 1) {
+                        console.log(data);
+                        if (data.status === 1) {
                         var user_avatar_image = $('#user_avatar_image');
                         user_avatar_image.attr("src", user_avatar_image.attr("src").split("?")[0] + "?" + Math.random());
                         var avatar_middle = $('.avatar-32');