上传图片问题

时间:2019-08-26 15:44:23

标签: laravel

我正尝试将图像直接上传到保管箱,我也使用croppie,所以 我的laravel上传代码是:

    $user = User::find($request->id_user);

    $image = $request->image;

    list($type, $image) = explode(';', $image);
    list(, $image)      = explode(',', $image);
    $image = base64_decode($image);
    $image_name = $user->rut.'_'.'photo'.'_'. date("d_m_Y") .'.jpg';
    $path = public_path('temp_images/'.$image_name);

    Storage::disk('dropbox')->putFileAs(
        '/intranet_jisparking_pictures/', 
        $image,
        'image.jpg' 
    );

问题是它在字符串上显示对成员函数getRealPath()的调用

我该如何解决?谢谢!

1 个答案:

答案 0 :(得分:0)

这是putFileAs类中Illuminate\Filesystem\FilesystemAdapter方法的标头:

/**
 * Store the uploaded file on the disk with a given name.
 *
 * @param  string  $path
 * @param  \Illuminate\Http\File|\Illuminate\Http\UploadedFile  $file
 * @param  string  $name
 * @param  array  $options
 * @return string|false
 */
public function putFileAs($path, $file, $name, $options = [])

看起来第二个参数应该是FileUploadedFile,但是您给它的结果是字符串的base64_decode

解决此问题的一种方法是在一个临时文件中自己创建一个UploadedFile的实例。有关示例,请参见this answer