uploaded a file with a controller, but looked no file extension.
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Image; class ImageIndexController extends Controller { public function index(){ return view('imageindex'); } public function store(Request $request){ $request->file('image')->move(public_path('item')); return view('imageindex'); } }
How come to fix it?
specify the extension with guessExtension method.
ImageIndexController.php
public function store(Request $request){ $filename = $request->file('image') . "." . $request->file('image')->guessExtension(); $request->file('image')->move(public_path('item'), $filename); return view('imageindex'); }
/image/index
I got it.
I want to display the uploaded image in view.
Before that, you want to make the file name arbitrary, such as date. It seems to be so easy.
$filename = date("YmdHis") . "." . $request->file('image')->guessExtension();
oh, OK.