php - Need help to import file.DAT into public/uploads folder using Laravel -
i'm trying import file.dat in public/uploads folder. didn't succeed. error appear
call member function getclientoriginalname() on non-object.
here's code
controller
<?php class importcontroller extends basecontroller { /* |-------------------------------------------------------------------------- | default import controller |-------------------------------------------------------------------------- | | may wish use controllers instead of, or in addition to, closure | based routes. that's great! here example controller method | started. route controller, add route: | | route::get('/', 'importcontroller@index'); | */ public function showimport() { return view::make('import'); } public function handleimport() { $file = input::file('file'); // file upload input field in form should named 'file' $destinationpath = 'public/uploads/'.str_random(8); $filename = $file->getclientoriginalname(); $uploadsuccess = $file->move($destinationpath, $filename); if( $uploadsuccess ) { return response::json('success', 200); // or redirect message file uploaded } else { return response::json('error', 400); } } }
view
<form action="{{ action('importcontroller@handleimport') }}" method="post" role="form"> <div class="form-group"> <label for="inputfile">file import</label> <input type="file" id="inputfile"> </div> <input type="submit" value="import" class="btn btn-primary" /> </form>
something wrong code?
depending on version, input::file('file');
can return different types. use dd($file)
see $file is, based on can check if file proceed.
Comments
Post a Comment