无法将图像数据写入路径。干预Image Laravel 5.3

时间:2017-05-11 17:25:34

标签: php laravel

当我尝试将图片上传到个人资料时,会出现错误

Can't write image data to path (C:\xampp\htdocs\laravel\blog\public\/uploads/avatars1494523098.jpg)

喜欢它无权访问uploads / avatars文件夹。我怎样才能解决这个问题?我在网上查看了不同的帖子,但我无法解决这个问题。

这是我的档案

UserController.php

public function profile() {
   return view('user/profile', array('user' => Auth::user()));
}

public function update_avatar(Request $request) {

    if ($request->hasFile('avatar')) {
        $avatar = $request->file('avatar');
        $filename = time() . '.' . $avatar->getClientOriginalExtension();
        Image::make($avatar->getRealPath())->resize(300,300)->save( public_path('/uploads/avatars' . $filename));

        $user = Auth::user();
        $user->avatar = $filename;
        $user->save();
    }

    return view('user/profile', array('user' => Auth::user()));
    //Image intervention
}

Profile.blade.php

@extends('layouts.default')

@section('content')
<div class="container first-container">
    <img src="/uploads/avatars/{{ $user->avatar }}" class="profielfoto">
    <h1>{{ Auth::user()->username }}'s Profiel</h1>

    <form enctype="multipart/form-data" action="profile" method="POST">
        <label for="">Update Profiel Foto</label>
        <input type="file" name="avatar">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        <input type="submit" class="pull-right btn btn-primary" value="Submit">
    </form>

</div>
@stop

提前致谢!

0 个答案:

没有答案