0

使用 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

4

1 回答 1

0

以下将解决您的查询,默认情况下,PHP 脚本的最大上传文件大小设置为 128 兆字节。但是,您可能想要更改这些限制。例如,您可以设置下限以防止用户将大文件上传到您的站点。为此,请更改 php.ini 文件中的 upload_max_filesize 和 post_max_size 指令。

upload_max_filesize = 20M
post_max_size = 21M

要验证upload_max_filesize指令和其他指令的当前值,可以使用phpinfo()函数。

如果您只想更改项目的这些值,您 也可以通过在.htaccess文件中提及来执行此操作。

// Replace xx with the maximum upload file size that you want to set
php_value upload_max_filesize xxM
// Replace xx with the maximum HTTP POST file size that you want to set
php_value post_max_size xxM
于 2019-09-13T10:47:50.960 回答