Laravel 4:上传后移动文件


Laravel 4: moving files once uploaded

我在尝试在我的应用程序上上传照片和任何类型的文件时遇到问题,因为上传但作为.tmp文件,它们在我的视图中无法正确显示

1.-我的表格,我试图上传带有姓名,组,电子邮件,描述和照片的成员

  {{Form::open(array('action' => 'AdminController@addMember','files'=>true)) }}
  {{ Form::label('file','Agregar Imagen',array('id'=>'','class'=>'')) }}
  {{ Form::file('file','',array('id'=>'','class'=>'')) }}
  <br/>
  {{Form::text('name','',array('class' => 'form-control','placeholder'=> 'Nombre'))}}
  {{Form::text('group','',array('class' => 'form-control','placeholder'=> 'Cargo'))}}
  {{Form::text('email','',array('class' => 'form-control','placeholder'=> 'Correo'))}}  
  {{Form::textarea('description','',array('class' => 'form-control','placeholder'=>''))}}
  <!-- submit buttons -->
  {{ Form::submit('Guardar') }}          
  <!-- reset buttons -->
  {{ Form::reset('Reset') }}          
  {{ Form::close() }}

2.-我在控制器中的上传功能

public function addMember()
{
    $name = Input::file('file')->getClientOriginalName();
    $newname = Input::file('file')->getFilename();    
    Input::file('file')->move(storage_path(),$name);
    $subpath = storage_path();
    $path = $subpath.'/'.$newname2;
    $name2 = Input::get('name');
    $email = Input::get('email');
    $description = Input::get('description');
    $group = Input::get('group');
    DB::table('contactgroups')->insert(
        array('group' => $group, 'name' => $name2, 'path' => $path, 'email' => $email, 'description' => $description)
    );
    $members = DB::table('contactgroups')->get();
    return View::make('admin.members',['members' => $members]);
} 

我知道我应该使用模型在我的数据库中上传东西,但现在这不是问题

3.- 我的显示视图

@extends('layouts.main')
@section('content')
    @foreach($members as $member)   
        <div class = "row fondue">
                <h3><div class="col-md-12"><b><?=$member->name ?></b></div></h3>    
                <div class="col-md-4"> <img src="<?=$member->path ?>" alt="Image" class = "contact-img"></div>
                <div class="col-md-4"><?=$member->description ?></div>
                <div class="col-md-4"><?=$member->email ?></div>
        </div>  
    @endforeach
@stop

仅此而已...信息保存在数据库中,但图像未在视图上正确显示,并且文件作为TMP文件上传,我不知道为什么

来自 Laravel 文档

移动上载的文件

Input::file('photo')->move($destinationPath);
Input::file('photo')->move($destinationPath, $fileName);

来源: http://laravel.com/docs/4.2/requests#files