You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Laravel网站部署后出现‘Image source not readable’图片上传失败问题

Troubleshooting "Image source not readable" in Laravel CMS Deployment

Hey there, let's work through this frustrating upload issue you're hitting. Local works fine, but production throws "Image source not readable"—I've been in this spot before, so here are targeted fixes to try:

1. Verify File Upload & Directory Permissions (Beyond 777)

Setting 777 is a quick test, but it's often not the full solution. Web servers usually run under a specific user (like www-data on Apache/Nginx), and ownership might be misaligned:

  • First, confirm the upload actually completes before image processing. Add a check after move() to log failures:
    use Illuminate\Support\Facades\Log;
    
    $uploadSuccess = $minphoto->move($minphoto_path, $minphoto_new_name);
    if (!$uploadSuccess) {
        Log::error("Failed to move file to: {$minphoto_path}");
        return back()->with('error', 'Upload failed at move step');
    }
    
  • Fix directory ownership (replace www-data with your web server user if different):
    chown -R www-data:www-data public/uploads
    
  • Use more secure permissions instead of 777:
    chmod -R 755 public/uploads
    chmod -R 775 public/uploads/img
    

2. Fix Path Discrepancies Between Local & Production

Hardcoding relative paths can break in production (especially if your server uses symlinks or a different public directory structure). Use Laravel's built-in path helpers to avoid this:

use Illuminate\Support\Facades\File;

// Use absolute path via public_path()
$minphoto_path = public_path('uploads/img');

// Ensure the directory exists (critical for production!)
if (!File::exists($minphoto_path)) {
    File::makeDirectory($minphoto_path, 0755, true, true); // Recursive + set permissions
}

$minphoto = $request->minphoto;
$minphoto_new_name = time() . $minphoto->getClientOriginalName();

// Move to absolute path
$minphoto->move($minphoto_path, $minphoto_new_name);

// Directly use the absolute path for Image processing
$imgPath = $minphoto_path . '/' . $minphoto_new_name;
$img = Image::make($imgPath)->resize(240, 338)->save();

This eliminates confusion between relative/absolute paths across environments.

3. Check Intervention Image Dependencies

Local environments often have GD/Imagick pre-installed, but production might not. Intervention Image requires one of these extensions to process images:

  • Check if GD is installed:
    php -m | grep gd
    
  • If missing, install it (Ubuntu example):
    sudo apt-get install php-gd
    sudo systemctl restart apache2 # Or nginx/php-fpm
    
  • For Imagick, use sudo apt-get install php-imagick instead.

4. Disable SELinux Temporarily (For RHEL/CentOS Servers)

SELinux can block write access even with correct file permissions. Test this by temporarily disabling it:

sudo setenforce 0

If the upload works, set a permanent SELinux rule instead of leaving it disabled:

sudo chcon -R -t httpd_sys_rw_content_t public/uploads
sudo setenforce 1

Start with steps 1 and 2 first—they're the most common culprits for this exact error. Let me know if any of these fix your issue!

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:47:48