我使用干预图像来调整 laravel 6 应用程序的图像大小。在完美运行的本地服务器上开发后,我尝试上传到共享主机,但出现错误。
Image source not readable
我已经尝试了我在 stackoverflow 和 laracast 上看到的所有内容。但他们不为我工作。
我试试
- 更改 index.html 中的基本路径
- 运行存储链接,在AppserviceProvider中
- 删除 public_html()。工作但没有将图像保存到 public_html->storage 文件夹
- dd() 请求路径,它是正确的
我的代码:
索引.php:
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$app->bind('path.public', function() {
return __DIR__;
});
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$app->bind('path.public', function() {
return __DIR__;
});
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
处理图像上传的 Post Controller
$image = $request->file('image'); $imagePath = $image->store('posts', 'public'); $image = Image::make(public_path($request->file('image')->getRealPath()))->fit(1263, 864); 返回$图像;$图像->保存();
BlogPost::create([
'title' => $request->title,
'image' => $imagePath,
'categories' => json_encode($request->categories),
'isEvent' => $request->isEvent,
'isEditorial' => $request->isEditorial,
'body' => $request->body,
]);
<form enctype="multipart/form-data" action="{{ route('post.store')}}" method="POST">
<div class="container">
@method('post')
@csrf
<div class="col-md-12">
<div class="card card-outline card-info">
<div class="card-body pad">
<div class="card card-primary">
<div class="card-header">
<h3 class="card-title">Add blog post</h3>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-12 col-md-6">
<div class="form-group">
<label for="customFile">Post Title</label>
<input type="text" class="form-control" name="title" id="title" maxlength="250">
<small id="character_txt" class="text-success"><span id="characters">255</span> characters left</small>
</div>
</div>
<div class="col-sm-12 col-md-6">
<label for="customFile">Upload Post image</label>
<div class="input-group input-group-md">
<input type="file" name="image" class="form-control">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
不可读的图像源指向 make()。我已经确认图像路径具有正确的路径。 错误页面