2016-01-14 61 views
2

我一直在這一段時間。希望我錯過簡單的東西,但我無法讓Laravel看到我通過表單上傳的文件。Laravel 5.2無法訪問上傳的文件

我試圖上傳,因爲有人註冊,但在這一點上,我甚至無法讓文件在這個簡單的測試控制器中被識別。

查看

@extends('layouts.app') 

@section('content') 
<div class="container"> 
<div class="row"> 
    <div class="col-md-8 col-md-offset-2"> 
     <div class="panel panel-default"> 
      <div class="panel-heading">Register</div> 
      <div class="panel-body"> 
       <form class="form-horizontal" role="form" method="POST" action="{{ url('/test') }}" enctype="multipart/form-data"> 
        {!! csrf_field() !!} 

        <div class="form-group{{ $errors->has('first_name') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">First Name</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="first_name" value="{{ old('first_name') }}" maxlength="50"> 

          @if ($errors->has('first_name')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('first_name') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('last_name') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">Last Name</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="last_name" value="{{ old('last_name') }}" maxlength="50"> 

          @if ($errors->has('last_name')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('last_name') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">E-Mail Address</label> 

         <div class="col-md-6"> 
          <input type="email" class="form-control" name="email" value="{{ old('email') }}" maxlength="255"> 

          @if ($errors->has('email')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('email') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">Password</label> 

         <div class="col-md-6"> 
          <input type="password" class="form-control" name="password" maxlength="60"> 

          @if ($errors->has('password')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('password') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">Confirm Password</label> 

         <div class="col-md-6"> 
          <input type="password" class="form-control" name="password_confirmation" maxlength="60"> 

          @if ($errors->has('password_confirmation')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('password_confirmation') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('type') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">Type</label> 

         <div class="col-md-6"> 
          <select class="form-control" name="type"> 
           <option {{ (old("type") == null ? "selected":"") }} disabled value="">--How will you use this site?--</option> 
           <option value="consultant" {{ (old("type") == 'consultant' ? "selected":"") }}>Consultant (Find Leads)</option> 
           <option value="sales" {{ (old("type") == 'sales' ? "selected":"") }}>Sales (Sell Leads)</option> 
           <option value="both" {{ (old("type") == 'both' ? "selected":"") }}>Both</option> 
          </select> 


          @if ($errors->has('type')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('type') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 


        <div class="form-group{{ $errors->has('about') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">About</label> 

         <div class="col-md-6"> 
          <textarea class="form-control" name="about" rows="5" maxlength="500" placeholder="Why should businesses accept your leads?"></textarea> 


          @if ($errors->has('about')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('about') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-md-4 control-label" for="file">Attach Profile Picture</label> 
         <div class="col-md-6"> 
          <input class="form-control" type="file" name="photo" id="photo"> 
          <p class="help-block">Max Size :500KB</p> 
         </div> 
        </div> 

        <div class="form-group"> 
         <div class="col-md-6 col-md-offset-4"> 
          <button type="submit" class="btn btn-primary"> 
           <i class="fa fa-btn fa-user"></i>Register 
          </button> 
         </div> 
        </div> 
       </form> 
      </div> 
     </div> 
    </div> 
</div> 
</div> 
@endsection 

控制器

<?php namespace App\Http\Controllers; 

use Symfony\Component\HttpFoundation\File\UploadedFile; 
use Illuminate\Http\Request; 

class TestController extends Controller { 
    /** 
    * Show the application dashboard to the user. 
    * 
    * @return Response 
    */ 
    public function index(Request $request) 
    { 
     if ($request->hasFile('photo')) { 
      return 'has file'; 
     } else { 
      return 'no file'; 
     } 
    } 
} 

回答

1

我的代碼是好的。只是需要加入php.ini文件,包括下面的大小尺寸限制(10 MB):

的php.ini:

upload_max_filesize = 10M 
post_max_size = 10M 
+0

我使用webfaction所以php.ini中的應用我安裝的/webapps/myapp/php.ini級別不存在,需要添加。 –