This code is working fine for me in laravel 5.5
public function add(Request $request)
{
if (isset($_POST['submit'])) {
$lid = DB::table('dc_dogs')->count();
$lid = $lid + 1;
$file = $request->file('ufile');
$file_name = $file->getClientOriginalName();
$file_ext = $file->getClientOriginalExtension();
$fileInfo = pathinfo($file_name);
$filename = $fileInfo['filename'];
$newname = $filename . $lid . "." . $file_ext;
$destinationPath = ASSET . 'upload/imgdogs';
echo $destinationPath;
$file->move($destinationPath, $newname);
$dogpic = Cln::fixValue($newname);
$dogname = ucfirst(Cln::fixValue($_POST['dogname']));
$sex = ucfirst($_POST['sex']);
$comments = Cln::fixValue($_POST['comments']);
$adopted = (isset($_POST['adopted']) == '1' ? '1' : '0'); ///added
$lastedit = date("Y-m-d H:i:s");
//echo "adpt=" . $adopted . "aaa";
if (!isset($error)) {
$postdata = array(
'dogpic' => $dogpic,
'dogname' => $dogname,
'sex' => $sex,
'comments' => $comments,
'adopted' => $adopted,
'lastedit' => $lastedit
);
DB::table('dc_dogs')->insert($postdata);
}
}
$title = 'Dog add';
$view = 'dog/add';
$layout = ViewLayout::getLayout('admin/addtp'); //ignore custom stuff
$content = View::make($view);
return view($layout)->with('content', $content)->with('title', $title);
}
But remember to have multipart/form-data
<form action='add' method='post' enctype="multipart/form-data">
// more.
If you prefer a static call, which I do then
change
use Illuminate\Http\Request;
to
use Illuminate\Support\Facades\Request;
change
public function add(Request $request)
to
public function add()
change
$file = $request->file('ufile');
to
$file = Request::file('ufile');
And the constant ASSET I defined in index.php
define('ASSET', realpath(dirname(__FILE__)). DS . 'assets' . DS);
DS needs a define also, otherwise use DIRECTORY_SEPARATOR
defined('DS') || define('DS', DIRECTORY_SEPARATOR);