php - Input::file() 返回 null Laravel

标签 php laravel laravel-4

我一直在写一个上传脚本,即使我使用的是 Laravel 内置的函数 Input::file() 它仍然返回 null。 我将发布我的家庭 Controller 代码。

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);
        }
    }

When I die(var_dump(Input::file('profile'))) 返回 null 这意味着它基本上不会将我的文件作为实际文件。当我 die(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"

关于php - Input::file() 返回 null Laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22513355/

相关文章:

php - 从php中的特定sql命令检索数据

php - PHP 和 Oracle 在企业环境中的配合程度如何?

mysql - 在 Laravel 中使用 raw 时字段列表中的未知列

mysql - 通过 URL 将 Laravel 连接到 Heroku 数据库

Laravel 4 - 更改资源根路由路径

php - Laravel Blade 模板变量

php - 如何将日期变量转换为月份名称 :

javascript - 无法从 Laravel 5 中的 PUBLIC 文件夹加载 AngularJs 文件

php - 命令 "make:seeder"未在 Lumen 5.2 中定义

php - MySQL 服务器消失了 - 在 mysql php 循环之后