uninjuredaccurate's avatar

File upload not working

Hi, I'm currently setting up a little webpage. Under 'profile', the users should be able to upload an image. But unfortunately, it does not work at all!

The following code examples all return NULL:

dd(Input::file('profile_image'));
dd($request->file('profile_image'));

When I do a dd() on the $_FILES var, I get the following:

array:1 [▼
    "profile_image" => array:5 [▼   
        "name" => ""
        "type" => ""
        "tmp_name" => ""
        "error" => 4
        "size" => 0
    ]
]

So apperently, I'm not able to upload files through laravel at all...

I need help! I'm stuck for about 3hours now..

Thanks! Flo

0 likes
6 replies
uninjuredaccurate's avatar

So, everything else is working fine (text fields, ...)

I removed all unnecessary parts:

<form role="form" enctype="multipart/form-data" action="{{ route('admin.usersedit', ['id' => $id, 'action' => $action]) }}" method="post">
    <div class="col-sm-6">
        <h3>Personal Data</h3>

        <!-- [...] -->
    </div>

    <div class="col-sm-6">
        <p>
            <h3>Profile Image</h3>

            <img src="{{ $user->profile_image }}" />

            <input type="file" name="profile_image" >
        </p>

        <p>
            <!-- [...] -->
        </p>

        <p>
            <!-- [...] -->

            <button type="submit" class="btn btn-default">Update</button>
        </p>
    </div>

    {{ csrf_field() }}
</form>
MWDeveloper's avatar

You should create a user migration where you should add the image property:

public function up() { Schema::table('users', function($table) { $table->string('image')->default('default.jpg'); }); }); } public function down() { Schema::table('clients', function($table) { $table->dropColumn('image'); }); }

don't forget to run the "php artisan migrate" command

Go to the user model and add the following:

protected $fillable = ['image'];

fraserk's avatar

I tried you upload form and it work. In the route you're calling why do you need 'action' => $action]

//I got this back
array:2 [▼
  "_token" => "tgsVE3z67UVeOG3IFkA9vHFAunNLXfOefGlD24PJ"
  "profile_image" => UploadedFile {#151 ▼
    -test: false
    -originalName: "DSC_0061.jpg"
    -mimeType: "image/jpeg"
    -size: 2034040
    -error: 0
    path: "C:\Users\#iamfraserk\AppData\Local\Temp"
    filename: "php8724.tmp"
    basename: "php8724.tmp"
    pathname: "C:\Users\#iamfraserk\AppData\Local\Temp\php8724.tmp"
    extension: "tmp"
    realPath: "C:\Users\#iamfraserk\AppData\Local\Temp\php8724.tmp"
    aTime: 2016-12-28 21:11:42
    mTime: 2016-12-28 21:11:42
    cTime: 2016-12-28 21:11:42
    inode: 0
    size: 2034040
    perms: 0100666
    owner: 0
    group: 0
    type: "file"
    writable: true
    readable: true
    executable: false
    file: true
    dir: false
    link: false
    linkTarget: "C:\Users\#iamfraserk\AppData\Local\Temp\php8724.tmp"
  }
]

uninjuredaccurate's avatar

I need that "action" thingy because of the way my routing and application is developed.

Thanks a lot for your help guys! After about 3-4hours of desperation, I found out the setting regarding the max. file size for uploads was set to 10Byte in php.ini

1 like

Please or to participate in this conversation.