Laracast13's avatar

Intervention Image and FilePond

Hi

Uisng FilePond

<input id="photos" name="image[]" type="file"multipledata-allow-reorder="true"data-max-file-size="3MB"data-max-files="3">
  
<script>
  FilePond.registerPlugin(FilePondPluginImagePreview);
const inputElement = document.querySelector('input[id="photos"]');
const pond = FilePond.create( inputElement );
FilePond.setOptions({
server:{
    url: '/photo', 
    process: '/uploads',
    revert: '/delete',
    headers: {
          'X-CSRF-TOKEN': '{{ csrf_token() }}'
          }
        }

}); 
</script>

....

   public function uploads(Request $request)
    {
     if($request->hasFile('image')){         
        $files = $request->file('image');       
           foreach ($files as $file) {
                    $filename = $file->getClientOriginalName();
                    $name_gen = hexdec(uniqid()).'.'.$file->getClientOriginalExtension();
                    $folder = uniqid();               
                   $file->move("uploads/" .,$name_gen);           
                   $url = "uploads/" . $name_gen;
                    return $url;
      }
     } 
     return '';
}

This function works upload image, now I want add Intervention Image

tried this but give response 500 error

   public function uploads(Request $request)
    {
     if($request->hasFile('image')){         
        $files = $request->file('image');       
           foreach ($files as $file) {
                    $filename = $file->getClientOriginalName();
                    $name_gen = hexdec(uniqid()).'.'.$file->getClientOriginalExtension();
                    $folder = uniqid();               
                   //$file->move("uploads/" .,$name_gen);         

       Image::make($file)->resize(1200, 1200, function ($constraint) {$constraint->aspectRatio();$constraint->upsize();})->move(uploads/" . $name_gen);

  
                   $url = "uploads/" . $name_gen;
                    return $url;
      }
     } 
     return '';
}
0 likes
13 replies
Snapey's avatar

We can't guess why there is a 500 error .... but you can look in the laravel logfile

Laracast13's avatar

"GD Library extension not available with this PHP installation"

jlrdw's avatar

This line looks wrong:

$file->move("uploads/" .,$name_gen);     stray dot:

jlrdw's avatar

But that is your code, I was just pointing out a possible error.

Snapey's avatar

This line

$file->move("uploads/" .,$name_gen);  

and this line

->move(uploads/" . $name_gen);

are both invalid php syntax

LOOK in the logfile

Laracast13's avatar
Image::make($file)->resize(1200, 1200, function ($constraint) {$constraint->aspectRatio();$constraint->upsize();})->move("uploads/" . $name_gen);

using this but same error

Snapey's avatar

WHAT error?

"same error" is absolutely no use for diagnosing the problem

yadav2brand's avatar

Damm even I am having a similar kind of issue, I have searched all over the internet and even have posted on number of threads on different forum, no solution seems to work. I am really frustrated, can anyone of you here help me resolve this issue, I am very much tired now. https://get-vidmate.com https://instasave.onl

Laracast13's avatar

It looks after update xampp disable GD Library In your php.ini you need enable ;extension=php_gd (reamove ; )

SagorIslam's avatar

$itemImages = $request->file('pd_images'); $images = []; if (isset($itemImages)){

        foreach ($request->file('pd_images') as $file){
            $slug = str_slug($request->pd_title);
            $itemImageName = $slug. '-'. $currentDate. '-'. uniqid(). '.'. $file->getClientOriginalName();

            if (!Storage::disk('public')->exists('portfolio/itemsDetails')){
                Storage::disk('public')->makeDirectory('portfolio/itemsDetails');
            }

            $portfolioItemImage = Image::make($file)->resize(610, 353)->stream();
            Storage::disk('public')->put('portfolio/itemsDetails/'.$itemImageName,$portfolioItemImage);

            $images[] = $itemImageName;
        }
    }
    $storeItem->pd_images = json_encode($images);

    $storeItem->save();

#Try this but can't help about JS codes

Please or to participate in this conversation.