davy_yg
103
19
Laravel

upload image

Posted 8 months ago by davy_yg

Hello,

I am trying to create upload image form:

seller.blade.php

<form action="{{ url('/daftarseller') }}">
<div id="upload">
KTP:
<input type="file" class="form-control" name="foto_profile" accept="image/png,image/jpeg" required><br>
Profile:
<input type="file" class="form-control" name="foto_ktp" accept="image/png,image/jpeg" required>

<br>
<input type="submit" value="Submit">
</form>

SellerController.php

public function add(Request $request)
{

    $original_name_ktp = $request->file('foto_ktp')->getClientOriginalName();
    $original_name_profile = $request->file('foto_profile')->getClientOriginalName();


    $request->file('foto_ktp')->storeAs(null, $original_name_ktp, 'foto_ktp');      
    $request->file('foto_profile')->storeAs(null, $original_name_ktp, 'foto_profile');

}

I get an error on:

$original_name_ktp = $request->file('foto_ktp')->getClientOriginalName();

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR) Call to a member function getClientOriginalName() on null

I am not sure what it does I basically want to copy the file that upload to the : foto_ktp directory (I already set it up on filesystems.php).

I also need to save the file name of the picture. Please help make this works.

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.