使用 laravel 6 时图片上传失败。
控制器
public function saveProduct(Request $request){
/*image upload process */
$productimage = $request->file('image');
$imageName = $productimage->getClientOriginalName();
$directory = 'Product-image/';
$imageUrl = $directory.$imageName;
$productimage->move($directory,$imageName);
$product= new Product();
$product->category_id = $request->category_id;
$product->brand_id = $request->brand_id;
$product->product_price = $request->product_price;
$product->product_quantity = $request->product_quantity;
$product->shortdescription = $request->shortdescription;
$product->longdescription = $request->longdescription;
$product->image = $imageUrl;
$product->public_status = $request->public_status;
$product->save();
return redirect('/product/add')->with('message','Prodect added saved successfully');
移民
Schema::create('products', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('category_id');
$table->integer('brand_id');
$table->float('product_price',8,2);
$table->integer('product_quantity');
$table->text('shortdescription');
$table->text('longdescription');
$table->text('image')->nullable();
$table->tinyInteger('public_status');
$table->timestamps();
});
路线
Route::get('/product/add', 'ProductController@index')->name('addproduct'); Route::post('/product/new', 'ProductController@saveProduct')->name('newproduct'); Route::get('/product/manage', 'ProductController@manageProduct')->name('manageproduct');
刀
<h3 class="text-center text-success">{{Session::get('message')}}</h3>
<form action="{{route('newproduct')}}" method="post" enctype="multipart/form-data">
@csrf