1
votes

I used intervention image to resize image for a laravel 6 app. After developing on local server, which worked perfectly, i try uploading to a shared hosting, but i am getting errors.

Image source not readable

I have tried everything i saw on stackoverflow, and laracast. but they are not working for me.

i try

  • changing the base path in index.html
  • Running storage link, in Appserviceprovider
  • removing public_html(). worked but not saving image to public_html->storage folder
  • dd() the request paths, its correct

my codes:

index.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 that handles image uploads

$image = $request->file('image'); $imagePath = $image->store('posts', 'public'); $image = Image::make(public_path($request->file('image')->getRealPath()))->fit(1263, 864); return $image; $image->save();

    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>

The Image source not readable is pointing to the make(). i have confirm the image path has the correct path. Error page

1

1 Answers

1
votes

I was having the same problem with Intervention and Laravel 6. After lots of research that never helped me, I did the following and it worked.

  1. Delete the storage link folder inside public
  2. Launch a terminal in your cpanel, cd to your project and run php artisan storage:link

I then tried uploading once again and it worked just fine