-1

i am uploading gif for my posts in laravel but gif is like an image its not moving or something like this

 <?php
 if($request->hasFile('gif')){

   $gif = $request->file('gif');
   $gif_filename = time() . '.' . $gif->getClientOriginalName();
   $gif_location = public_path('/images/' . $gif_filename);
   Image::make($gif)->save($gif_location);
 }

  $post->gif = $gif_filename;
      $post->save();
?>

here is the code what I am using I think everything is kinda correct

DaFois
  • 2,197
  • 8
  • 26
  • 43
Alex Tsirikidze
  • 21
  • 1
  • 2
  • 9

3 Answers3

0

I use this method

if(Input::hasFile('imagen')) {
   $time = Carbon::now()->format('Y-m-d');
   $image = $request->file('imagen');
   $extension = $image->getClientOriginalExtension();
   $name = $image->getClientOriginalName();
   $fileName = $time."-".$name;
   $image->move(storage_path(),$fileName);
}

Please try this and let me know how it works :)

0

An easy way to update and save is to do it like this:

public function store(Request $request)
{
    $imgLocation = Storage::disk('public')->put(time() . '.' . $request->file('image')->getClientOriginalName(), $request->gif), $request->file('gif'));

    // This would save it to the gifs table if you need something like it, otherwise skip this creation
    $gif= Gif::create([
        'name' => $request->name,
        'path' => $imgLocation
    ]);

    if ($gif) {
        return response()->json("Success!"); 
    }

    return response()->json("Error!"); // or you return redirect()...
}
utdev
  • 3,942
  • 8
  • 40
  • 70
0
$image = $request->file('image');
  
if(isset($image)) {
    if($image->getClientOriginalExtension()=='gif'){
        $image = $request->file('image');
        $extension = $image->getClientOriginalExtension();
        $name = $image->getClientOriginalName();
        $fileName = 'exerciseimages'."-".$name;
        $image->move('storage/courseimages/',$fileName);
    }
    else{
          $fileName = 'exerciseimages'.'-'.uniqid().'.'.$image->getClientOriginalExtension();
    
        if(!Storage::disk('public')->exists('courseimages')){
            Storage::disk('public')->makeDirectory('courseimages');
        }
        $amenitiesimg = Image::make($image)->resize(250,250)->stream();
        Storage::disk('public')->put('courseimages/'.$fileName, $amenitiesimg);

       
    }
}
else {
    $fileName = 'default.png';
}
Syscall
  • 19,327
  • 10
  • 37
  • 52
Rahul Dev
  • 19
  • 1