在Laravel中上传文件 [英] File uploading in Laravel

查看:62
本文介绍了在Laravel中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

曾经尝试过很多事情来将文件保存到Laravel的适当目录中.我的控制器中有以下内容. $ files和$ folder变量正确.文件夹创建正确,但是文件不会保存到该文件夹​​:

Been trying tons of things to save a file upload into the proper directory in Laravel. I have the following in my controller. The $files and $folder variables are correct. The folder is being created properly but the file will not save to the folder:

$files = $request->file('current_plan_year_claims_data_file_1');
$folder = public_path(). "\storage\\$id";

if (!File::exists($folder)) {
    File::makeDirectory($folder, 0775, true, true);
}

if (!empty($files)) {
    foreach($files as $file) {
        // Storage::disk('local')->put($file->getClientOriginalName(), file_get_contents($file));
        Storage::disk(['drivers' => 'local', 'root' => $folder])->put($file->getClientOriginalName(), file_get_contents($file));

        // Storage::put($file->getClientOriginalName(), $folder);

    }
} 

推荐答案

您应尝试使用此代码. storage::disk行中的错误.编写驱动程序而不是驱动程序.

you should try this code. error in your storage::disk line. write driver instead of drivers.

    $files = $request->file('current_plan_year_claims_data_file_1');
    $folder = public_path(). "\storage\\$id";


     if (!File::exists($folder)) {
        File::makeDirectory($folder, 0775, true, true);
    }

    if (!empty($files)) {
        foreach($files as $file) {
             Storage::disk(['driver' => 'local', 'root' => $folder])->put($file->getClientOriginalName(), file_get_contents($file));
        }
    } 

这篇关于在Laravel中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆