Home > OS >  Laravel request hasFile not registered when uploading from android/ios chrome
Laravel request hasFile not registered when uploading from android/ios chrome

Time:01-26

I have a strange issue when uploading files through an android/ios chrome browser. I have a whole condition thatchecks

public function store(Request $request)
{
   ...
   if ($request->hasFile('photos')) {
       $this->createPhotos($post, $request['photos']);
   }
   ...
}

And here is the createPhotos function

public function createPhotos(Post $post, $photos)
{
    
    foreach ($photos as $photo) {
        $p = Image::make($photo->getRealPath());
        $filename = md5($photo->getRealPath() . Carbon::now()) . '.jpg';
        $p->orientate();
        $p->resize(null, 500, function ($constraint) {
            $constraint->aspectRatio();
        });

        $p->stream();

        Storage::disk(env('APP_FILESYSTEM'))->put('posts/' . $filename, $p);

        $average_color = $this->getAverageColor($photo->getRealPath());

        $post_photo = new \App\Photo();
        $post_photo->name = $filename;
        $post_photo->height = $p->height();
        $post_photo->width = $p->width();
        $post_photo->average_color = $average_color;
        $post_photo->post_id = $post->id;
        $post->photos()->save($post_photo);
    }
}

It works fine when uploading from desktop but the problem appears when uploading from mobile browser only. This whole hasFile condition gets skipped.

CodePudding user response:

None of the things i was concerned about was the problem.. Apparently the problem was inside the server's php.ini file where upload_max_filesize = 2M ... and stubbornly i was constantly uploading smartphone camera photos larger than 2MB ...

  • Related