输入:: file()返回null Laravel [英] Input::file() returning null Laravel

查看:298
本文介绍了输入:: file()返回null Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在编写一个上载脚本,即使我使用的是Laravel内置函数Input :: file(),它仍然返回null. 我要发布我的家庭控制器代码.

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后端失败了.这是真的,还是我只是想念一些东西?

When I die(var_dump(Input::file('profile'))) returns null which means it is basically not taking in my file as an actual file. When I do die(var_dump(Input::get('profile'))) it returns the image name meaning that my uploading script is working but the Laravel backend is failing. Is this true, or am I just missing something?

这是我的HTML表单内容:

Here is my HTML form stuff:

@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

推荐答案

我在正常形式下也遇到了同样的问题.我忘了补充:

I had the same problem in a normal form. I forgot to add:

enctype="multipart/form-data"

这篇关于输入:: file()返回null Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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