dtommy79's avatar

Image upload

Hi,

I created a blog on localhost. I upload it to a live server. I placed the content of the "public" folder in the "public_html", and I uploaded the rest of the app outside the "public_html" in a separate folder.

When I create a category or a post where I can upload images, the images won't upload. I guess I need to change some path.

Originally I used this code on one of my controller:

$category = Image::make($image)->resize(1920,479)->stream();
            Storage::disk('public')->put('category/' . $imagename, $category);

Since I no longer have a "public" folder, I guess it needs to be changed, but not sure how. Also I'm not sure if I need to change anything in "config/filesystems.php"

0 likes
2 replies
MdAzizurRahman's avatar

public function store(Request $request) { $this->validate($request,[ 'title' =>'required', 'image' => 'mimes:jpeg,jpg,bmp,png'

    ]);


     

      $image = $request->file('image');
    $slug = str_slug($request->title);
    if (isset($image))
    {
        $currentDate = Carbon::now()->toDateString();
        $imagename = $slug.'-'.$currentDate.'-'. uniqid() .'.'. $image->getClientOriginalExtension();
        $image_resize = Image::make($image->getRealPath());   
        $image_resize->resize(1600,1066);
        if (!file_exists('storage/uploads/post'))
        {
            mkdir('storage/uploads/post',0777,true);
        }
        $image_resize->save('storage/uploads/post/'.$imagename);
    }else{
        $imagename = "default.png";
    }

    $post = new Post();
    $post->title = $request->title;
    $post->slug = str_slug($request->title);
    $post->image = $imagename;
    $post->save();
    Toastr::success('Post Successfully Save:)','Success');
    return redirect()->route('admin.post.index');
  

}

// follow this link https://github.com/mdazizurrahman/DownloadThemeProject/blob/master/app/Http/Controllers/Admin/PostController.php

Please or to participate in this conversation.