gpt4 book ai didi

php - 干预/图片上传错误{{图片来源不可读}}

转载 作者:可可西里 更新时间:2023-10-31 22:11:37 29 4
gpt4 key购买 nike

我正在尝试在 Laravel 5.1 中添加个人资料图片上传。我使用了 Intervention/Image 包,但是当我尝试上传图像时出现此错误:

NotReadableException in AbstractDecoder.php line 302: Image source not readable

这是我的 PhotoController:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Image;
use Input;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class PhotoController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index() {}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create() {}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$img = Image::make($request->file('photo'));
$img->save('image.png');
}

/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id) {}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id) {}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id) {}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id) {}
}

这是我的 html 表单:

<header>
<div class="student_profile_sub_header w100">
<div class="container ccenter">
<div class="student_profile_name">
<h4>{{$student->name}} {{$student->surname}}</h4>
</div>
<div class="student_profile_image">
<img src="{{asset('assets/profile_image.png')}}">
</div>

<form method="POST" action="../student/profile/imageupload">
{!! csrf_field() !!}
<input type="file" name="photo">
<input type="submit" value="Upload Image" name="submit">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</form>
</div>
</div>
</header>

最佳答案

在您的表单标签中添加以下参数:

enctype="multipart/form-data"

并在 make 中对此进行更改:

$img = Image::make($request->file('photo')->getRealPath());

关于php - 干预/图片上传错误{{图片来源不可读}},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36157824/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com