weixin_33721344 2016-11-05 12:44 采纳率: 0%
浏览 95

laravel无法“ move()”文件

I am using Laravel 5.3.
And I use cropper https://github.com/fengyuanchen/cropper to crop image and then upload it to back end via ajax.

$('#uploadAvatar').on('click', function (e) {

    $("#image").cropper('getCroppedCanvas').toBlob(function (blob) {
        var formData = new FormData();

        formData.append('croppedImage', blob);

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        $.ajax({
            type: "POST",
            url: "{{ url('/change-avatar') }}",
            processData: false,
            contentType: false,
            data: formData
        }).done(function (response) {
            //...
        }).fail(function (data) {
            //...
        });
    });
});

the headers of ajax request is like this: enter image description here

Laravel get the image and do something like this:

public function changeAvatar (Request $request)
{
    $file = $request->croppedImage;
    $input = array('image' => $file);
    $rules = array(
        'image' => 'image'
    );
    $validator = \Validator::make($input, $rules);
    if ( $validator->fails() ) {
        return \Response::json([
            'success' => false,
            'errors' => $validator->getMessageBag()->toArray()
        ]);

    }

    $destinationPath = '/images/uploads/';
    $user=\Auth::user();
    $fileName = $user->id . '_' . time() . '.'.$file->clientExtension();
    $file->move($destinationPath, $fileName);
    //dd($file);
    $user ->avatar = $destinationPath.$fileName;
    $user ->save();

    return \Response::json([
        'success'=>true,
        'avatar'=>asset($destinationPath.$fileName),
    ]);

}

In above method, the line $file->move($destinationPath, $fileName); not working.
Why is it?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用lstm来预测股票价格
    • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
    • ¥170 如图所示配置eNSP
    • ¥20 docker里部署springboot项目,访问不到扬声器
    • ¥15 netty整合springboot之后自动重连失效
    • ¥15 悬赏!微信开发者工具报错,求帮改
    • ¥20 wireshark抓不到vlan
    • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
    • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
    • ¥15 stata安慰剂检验作图但是真实值不出现在图上