You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

Laravel上传图片显示异常,日志报finfo_file()未定义错误求助

Hey there! The error you're seeing (Call to undefined function Illuminate\Filesystem\finfo_file()) is caused by the PHP fileinfo extension not being enabled on your server. This extension is required by Laravel's Filesystem component to detect file MIME types, which explains why your uploaded images are ending up corrupted—Laravel can’t properly process them without this critical extension.


How to Fix This

Depending on your environment (local development or production server), follow these tailored steps:

1. Local Development Environment (XAMPP/WAMP/MAMP)

  • Locate your php.ini file. For XAMPP, this lives in xampp/php/php.ini; for WAMP, check wamp/bin/php/php[your-version]/php.ini.
  • Open it in a text editor and search for this line:
    ;extension=fileinfo
    
  • Remove the leading semicolon (;) to uncomment the line, so it becomes:
    extension=fileinfo
    
  • Restart your web server (Apache/Nginx) and PHP service to apply the changes.

2. Production Server

Shared Hosting (cPanel/Plesk)
  • Log into your hosting control panel.
  • Find the "PHP Selector" or "PHP Options" section.
  • Look for the fileinfo extension in the available list, check the box next to it, and save your changes.
VPS/Dedicated Server (Linux)
  • For Debian/Ubuntu-based systems:
    sudo apt-get update
    sudo apt-get install php-fileinfo
    # Restart PHP service (adjust version to match your PHP install, e.g., php8.1-fpm)
    sudo systemctl restart php7.4-fpm
    
  • For CentOS/RHEL-based systems:
    sudo yum install php-fileinfo
    # Restart PHP service
    sudo systemctl restart php-fpm
    

Verify the Fix

To confirm the extension is enabled, create a temporary phpinfo.php file in your project’s public directory with this content:

<?php phpinfo(); ?>

Visit this file in your browser (e.g., https://yourdomain.com/phpinfo.php) and search for "fileinfo". You should see a section confirming it’s active.

Once the extension is working, try uploading a new image—it should display correctly. Note that any images you uploaded while the extension was missing will likely still be corrupted, so you’ll need to re-upload those.

内容的提问来源于stack exchange,提问作者365Techsolutions

火山引擎 最新活动