duan0504 2014-02-13 09:20
浏览 15

Laravel 4 Form:带文本字段的图像文件上传

I would like to design a form in Laravel which takes an image the User has selected, uploads it to the server and stores the image path in a 'image' field and also accepts a 'text' field which describes the image. I do not know how to store both the text field and image as an array to pass to the controller.

The Form

<div class="form-group">
{{ Form::label('description', trans('main.poster')) }}
{{ Form::text('description', Input::old('poster'), array('class' => 'form-control')) }}
</div>
<div class="form-group">
{{ Form::file('image','files' => true) }}
</div>
<button type="submit" class="btn btn-success">{{ trans('dash.update') }}</button>

Controller

public function store()
{

$input = array('image' => Input::file('image'));

    if ( ! $this->validator->setRules('image')->with($input)->passes())
    {
        return Redirect::back()->withErrors($this->validator->errors());
    }

    $this->title->uploadImage($input);

    return Redirect::back()->withSuccess( trans('main.uploaded image success')        );

Upload image

public function uploadImage(array $input)
{   
 $name  = str_random(25);
    $insert = array('image' => asset('assets/images/'.$name.'.jpg'), );

    $this->images->saveTitleImage($input, $name);


}

Save image path

public function saveTitleImage($input, $name)
{
    $encoded = Imagine::make($input['image']->getRealPath())
        ->encode('jpg');

    Imagine::make($encoded)->save(public_path('assets/images/'.$name.'.jpg'));  
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序