Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lozza's avatar
Level 4

Can't upload images in filament admin panel

I have the following code in my laravel 10 project which works great in my local environment (macbook/herd etc..) but when running on my nginx server (php8.2) I get an error File of Invalid Type Expects or image/*

   FileUpload::make('popup_image')
        ->label('Popup Image')
        ->image()
        ->directory('popups')
        ->nullable(),

I have created the storage link!

Any ideas greatfully received :)

0 likes
3 replies
LaryAI's avatar
Level 58

The error message "File of Invalid Type" suggests that the server is not recognizing the uploaded file as a valid image. Here are a few steps you can take to troubleshoot and resolve this issue:

  1. Check MIME Types on the Server: Ensure that your server is configured to recognize image MIME types. You can do this by checking your nginx configuration. Make sure that the mime.types file includes the necessary image types, such as image/jpeg, image/png, etc.

  2. Verify PHP Fileinfo Extension: The PHP fileinfo extension is used to determine the MIME type of a file. Ensure that this extension is enabled in your php.ini file on the server. You can check this by running php -m and looking for fileinfo in the list of loaded extensions.

  3. Check File Permissions: Ensure that the directory where you're trying to upload images has the correct permissions. The web server user (e.g., www-data for Nginx) should have write permissions to the storage and public directories.

  4. Validate File Uploads: Double-check the validation rules in your Laravel application to ensure they allow the image types you are trying to upload. You can specify allowed MIME types in your validation rules.

  5. Debugging: Add some debugging to check the MIME type of the uploaded file. You can do this by logging the MIME type in your controller or by using a middleware to inspect the request.

  6. Check for File Corruption: Ensure that the files are not getting corrupted during the upload process. You can try uploading different image files to see if the issue persists.

Here's a sample code snippet to log the MIME type of the uploaded file:

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

public function uploadImage(Request $request)
{
    if ($request->hasFile('popup_image')) {
        $file = $request->file('popup_image');
        $mimeType = $file->getMimeType();
        Log::info('Uploaded file MIME type: ' . $mimeType);
    }
}

By following these steps, you should be able to identify and resolve the issue with image uploads on your Nginx server. If the problem persists, consider checking the server logs for more detailed error messages.

vincent15000's avatar

Perhaps a problem with the detection of the mime type ?

Lozza's avatar
Level 4

I think it is but I don't know how to fix it!! I have (for now) changed to file upload instead which works fine!! I have checked the nginx conf and that lists all image types...

Please or to participate in this conversation.