繁体   English   中英

Laravel 4将图像上传到服务器

[英]Laravel 4 Upload Image to server

我正在尝试将图像上传到laravel,但遇到了一些麻烦:S

我的观点:

<form role="form" method="post" action="{{url('admin/test')}}" id="formm" >
        <input  type="file" placeholder="browse" id="imagen_item" name="imagen_item" accept="image/*"/>
        <input type="submit" style="font-size: 20px" class="btn btn-primary" value="Guardar">
</form>

我的routes.php

Route::post('admin/test','AdminController@test');

我的控制器

public function test()
{
    $file = Input::file('imagen_item');
    var_dump($file);
    $destinationPath = 'uploads/';
    if(is_object($file))
    {
        $filename = $file->getClientOriginalName();
        $upload_success = Input::file('imagen')->move($destinationPath, $filename);
        if( $upload_success ) {
            echo 'save this url: '.$filename." in the DB";
        }
    }
}

提交表单后得到的结果是:

null
A
A.A

如此明显的问题是我不是从输入表单中抽出图像..但是为什么呢? 我同名...谢谢!

解决了! 我将表单标签更改为:

    {{ Form::open(array('url' => 'admin/rnew_item', 'files' => true,'id'=>'formm')) }}

并且为:

    {{ Form::close() }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM