I've been writing an uploading script and even though I'm using the Laravel built in function Input::file() it still returns null. I am going to post my Home Controller code.

public function handleUpload()
    {
        $user = Auth::user();
        $username = $user->username;
        $userId = $user->id;
        $path_to_users = "users";
        $user_profile_img = 'users/'.$username.$userId.'/'.$username.'image001.jpg';
        $user_path_profile = "users/$username$userId";
        $user_image_name = $username.'image001.jpg';
        if(file_exists($path_to_users))
        {
            if(file_exists("$user_path_profile")){
                $file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
            } else {
            mkdir("$user_path_profile");
            $file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
        }

        } else {
            mkdir("users");
            mkdir("$user_path_profile");
            $file = Input::file('profile')->move("$user_path_profile/", $user_image_name);
        }
    }

当我死的时候(var_dump(Input::file('profile'))返回null,这意味着它基本上不会将我的文件作为实际文件接收.当我死(var_dump(Input::get('profile'))时,它返回图像名,这意味着我的上传脚本正在工作,但Laravel后端失败.这是真的,还是我错过了什么?

以下是我的HTML表单:

@if($user->id == $userProf->id)

                            <div class="fileUpload button-success pure-button">  
                                <span>Upload</span>
                                <form action="{{action('HomeController@handleUpload')}}" method="POST" enctype="multipart/form-data">
                                    <input type="file" name="profile" class="upload" />

                                </form>
                            </div>
                            @endif

推荐答案

在正常情况下,我也有同样的问题.我忘了加一句:

enctype="multipart/form-data"

Laravel相关问答推荐

Laravel Livewire与自定义JS有关的多姆问题

如何使用PHP版本8.2.6安装beyondcode/laravel-websockets软件包?

如何让 Laravel 的 Collection 表现得像一个流?

Laravel 语法 GroupBy 获取列到数组

按回车键时如何防止此功能运行?

Laravel 验证 - 不同的属性规范

在 Laravel 中设置多个 Vue 组件的问题

Laravel 5.4 - 如何为同一个自定义验证规则使用多个错误消息

如何在 laravel 中安装 PHPExcel 库?

Laravel 表 * 没有名为 * 的列

Laravel 5 - 多对多 - Attach versus Save

如何在 Laravel 中将秒转换为天小时分钟

Laravel 模型:模型属性在哪里?

Laravel Eloquent ORM 复制

如何运行artisan命令计划:在托管服务器上运行? (Laravel )

Laravel 验证 pdf mime

Laravel 中的单会话登录

Laravel 如何具体构建和判断 CSRF 令牌?

如何在特定项目中禁用初始化 JS/TS 语言功能?

如何在 laravel 表单验证错误消息中给出自定义字段名称