laravel - 文件无法上传到上传文件夹

时间:2016-04-25 18:38:20

标签: php file laravel upload

这是我提出的previous问题的后续问题。我按照指示添加了代码,但现在我的表单在我的表单到达上传字段时得到的所有内容我只是将重定向的bacl重定向到表单。

以下是我的观点:

@extends('app');

@section('content');
    <h1>Add a new item</h1>
    <hr />
    <content>
        <div class="form-group">
        {!! Form::open(['route' => 'item.store', 'files' => true]) !!}
        {!! Form::label('name', "Name") !!}
        {!! Form::text('name', null, ['class' => 'form-control']) !!}

       {!! Form::label('filename', "File Name") !!}
        {!! Form::file('filename', null, ['class' => 'form-control']) !!}

        {!! Form::label('description', 'Description') !!}
        {!! Form::textarea('description', null, ['class' => 'form-control']) !!}
        {!! Form::submit('Add Item', ['class' => 'btn btn-primary form-control']) !!}

    </content>
</div>

@stop

这是我的控制器

      public function store(Requests\CreateItem $request)
    {


        Item::create($request->all());

//        if (Input::hasFile('filename')) {
//            $file = $request->file('filename');
//            $file->move(public_path().'/uploads', $file->getClientOriginalName());
//
//            echo "File Uploaded";
//
//        }
        dd(Input::all());




    }

这是我的路线

    <?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::resource('item', 'ItemController');

Route::get('/', function() {
    return view('welcome');
});
Route::auth();

Route::get('/home', 'HomeController@index');
Route::post('/item/create', ['as' => 'item.store', 'uses' => 'ItemController@store']);

Route::get('/item', 'ItemController@store');

//Route

有什么建议吗? 编辑:这是我的Requests \ CreateItem.php文件

    <?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class CreateItem extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true; // for now
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => 'required|min:3',
            'filename', 'required|min:7',

        ];
    }
}

2 个答案:

答案 0 :(得分:0)

首先,我认为你应该删除这一行:

[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------

如果你想改变路线中的某些思路(名称或控制器方法)你应该把它放在这一行之前:

Route::post('/item/create', ['as' => 'item.store', 'uses' => 'ItemController@store']);

您的路线顺序错误,这就是您回到表单的原因。

答案 1 :(得分:0)

我想我可能找到了答案。 'filename', 'required|min:7',应为filename => 'required|min:7'