繁体   English   中英

laravel-上传并显示图像

[英]laravel - upload and show image

我尝试上传更大的图片,但不起作用。 100KB以下的图片可以上传,但较大的图片不能上传。

我在服务器php上设置了upload_max_filesize = 32M post_max_size = 32M

但仍然无法上传。

上传代码:

public function upload(Request $request)
{
    $last_row = DB::table('ref')->latest()->first();

 $destinationPath = 'images/ref/'.$last_row->id; // upload path
  if(!File::exists($destinationPath)) {
     File::makeDirectory($destinationPath, $mode = 0777, true, true);
    }

  $insertedId =$last_row->id;
    $input['image'] = time().'.'.$request->image->getClientOriginalExtension();
    $request->image->move(public_path($destinationPath), $input['image']);
    $input['idDor'] = $last_row->id;
     $input['title'] = $request->title;
    ImageGallery_referencesve::create($input);

  return view('ItemCRUDref.image-gallery',compact('insertedId'));

}

我可以理解为什么设置max_filesize = 32M时无法上传100KB以上的图像。 任何想法?

当我上传较大的图片时,它会使用索引页面

      public function index()
    {
 $images =DB::table('ref')->get();
  return view('ItemCRUD.ref',compact('images'));
     }

我的blade.php

 <form action="{{ url('ref') }}" class="form-image-upload" method="POST" enctype="multipart/form-data">

<div class="row">
     <div class="col-md-5">
        <strong>Prior:</strong>
       {!! Form::select('title', array('Yes' => 'Yes','No' => 'No'), 'No', array('class' => 'form-control')) !!}
    </div>
    <div class="col-md-5">
        <strong>Add:</strong>
        <input type="file" name="image" class="form-control">
    </div>
    <div class="col-md-2">
        <br/>
        <button type="submit" class="btn btn-success">Upload</button>
    </div>
</div>

我认为您在错误的文件中更改了设置。

在您的laravel应用中进行如下测试:

Route::get('/php', function () {
    phpinfo();
});

并搜索到Loaded Configuration File的确切路径

在此处输入图片说明

然后打开该文件并在此处更改以下设置:

upload_max_filesize
post_max_size

哦,还有一件非常重要的事情,您需要在进行更改后重新启动apache或nginx服务器!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM