$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';
$file->move($destinationPath, $newname);
$dogpic = $newname;
$dogname = ucfirst(Request::input('dogname'));
$sex = ucfirst(Request::input('sex'));
$comments = Request::input('comments');
$adopted = !empty(Request::input('adopted')) ? '1' : '0';
$lastedit = date("Y-m-d H:i:s");
$postdata = array(
'dogpic' => $dogpic,
'dogname' => $dogname,
'sex' => $sex,
'comments' => $comments,
'adopted' => $adopted,
'lastedit' => $lastedit
);
DB::table('dc_dogs')->insert($postdata);
I made ASSET above a constant to path. Use your path
To display:
<img width="100" style="border: none;" src="<?php echo DIR . 'assets/upload/imgdogs/' . $row->dogpic; ?>" alt="">
Where DIR is a constant for base url.
I also in blade:
<img src="{{ asset('assets/upload/imgdogs') . '/' . $row->dogpic }}" alt="" class="image">
All the above works been working since laravel 5.1 through laravel 8.
Also the constant for asset:
define('ASSET', realpath(dirname(__FILE__)). DS . 'assets' . DS);
DS is
defined('DS') || define('DS', DIRECTORY_SEPARATOR);