2016-03-22 24 views
6

Tôi đang cố gắng thêm ảnh hồ sơ tải lên trong Laravel 5.1. Tôi đã sử dụng Intervention/Image Gói nhưng khi tôi cố gắng để tải lên các hình ảnh tôi nhận được lỗi này:Lỗi can thiệp hình ảnh/can thiệp {{Nguồn ảnh không thể đọc được}}

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

Đây là PhotoController tôi:

<?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) {} 
} 

Đây là hình thức html của tôi:

<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> 
+0

cung cấp đường dẫn tệp đích của bạn bên trong phương thức lưu –

Trả lời

8

Thêm tham số sau trong thẻ hình của bạn:

enctype="multipart/form-data" 

Và thay đổi cho điều này trong thực hiện:

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

Cảm ơn rất nhiều Thiago Alves. – arispapapro

1

Hãy thử sử dụng laravel tập thể, Hãy chắc chắn rằng các tập tin bạn đã kiểm tra là true nếu bạn đang sử dụng laravel tập thể

{{ Form::open(['route'=>'your-route', 'class'=>'form',**'files'=>true**]) }} 
{{ Form::close()}}` 

, sau đó khi yêu cầu tập tin của bạn trong chức năng lưu trữ thêm getRealPath() như thế này Image::make(Input::file('artist_pic')->getRealPath())->resize(120,75);

Các vấn đề liên quan