mathishuettl's avatar

MimeTypeGuesser -> FileNotFoundException

Hello,

I have a strange problem on a project. There is a file-upload function where users can upload images and videos. Sometimes this problem appears and sometimes it doesn't. It's only when the user uploads a video. that is greater then about 2 mb

https://imgur.com/lNRGIkC

public function upload(Request $request) {
      $rules = [
          "tags" => "required",
          "accept_rules" => "required|in:true"
      ];

      $mime = $request->file("file")->extension();
      if ($mime == "png" || $mime == "jpg" || $mime == "jpeg") {
          $rules["file"] = "required|file|mimes:jpeg,jpg,png,webm,mp4|max:1024";
      } elseif ($mime == "mp4" || $mime == "webm") {
          $rules["file"] = "required|file|mimes:jpeg,jpg,png,webm,mp4|max:32768";
      } else {
          $rules["file"] = "required|file|mimes:jpeg,jpg,png,webm,mp4|max:32768";
      }

      if ($request->has("link")) {
          $rules["link"] = "url";
      }

      
      switch ($request->file("file")->extension()) {
          case "png":
          case "jpg":
          case "jpeg":
              $post->type = "image";
              $post->media = $request->file("file")->store("uploads");

              $image = Image::make($request->file("file")->path());
              $thumb_path = "thumbs/" . md5($request->file("file")->getClientOriginalName() . time()) . "." . $request->file("file")->extension();
              $image->fit(300, 300)->save(storage_path("app/public/") . $thumb_path);
              $post->thumb = $thumb_path;
              break;
          case "mp4":
          case "webm":
              $post->type = "video";
              $post->media = $request->file("file")->store("uploads");
    
              $video_thumb_url = "thumbs/" . md5($request->file("file")->getClientOriginalName() . time()) . ".png";
              $video_thumb_path = storage_path("app/public/") . $video_thumb_url;
              $mov = new \ffmpeg_movie(storage_path("app/public/") . $post->media);
              $frame = $mov->getFrame(10);
              if ($frame) {
                  $gd_image = $frame->toGDImage();
                  if ($gd_image) {
                      imagejpeg($gd_image, $video_thumb_path);
                      imagedestroy($gd_image);
                      $post->thumb = $video_thumb_url;
                  }
              }
              break;
      }
}
0 likes
1 reply

Please or to participate in this conversation.