Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 为什么不更新图片';检测不到上传的文件?_Laravel_Laravel 5_File Upload_Image Uploading - Fatal编程技术网

Laravel 为什么不更新图片';检测不到上传的文件?

Laravel 为什么不更新图片';检测不到上传的文件?,laravel,laravel-5,file-upload,image-uploading,Laravel,Laravel 5,File Upload,Image Uploading,我正在使用laravel 5为个人资料创建编辑表单,并可以更新表单中的图片 我想以编辑形式存储新图像。我在edit.blade中使用此代码按用户获取图像 查看: {!! Form::model($dataItemregistration,['method' => 'PATCH', 'action' => ['Modul\ProfilController@update', $dataItemregistration->ItemRegistrationID, 'files' =&g

我正在使用laravel 5为个人资料创建编辑表单,并可以更新表单中的图片

我想以编辑形式存储新图像。我在edit.blade中使用此代码按用户获取图像

查看:

{!! Form::model($dataItemregistration,['method' => 'PATCH', 'action' => ['Modul\ProfilController@update', $dataItemregistration->ItemRegistrationID, 'files' => true] ]) !!}
<div class="form-group">
    <div class="row">
        <div class="col-lg-3"> 
            {{ Form::label('pic', 'Gambar (Saiz gambar, 250x300px)') }}
        </div>
        <div class="col-lg-7">
            {!! Form::file('gambar', array('class' => 'form-control')) !!}
        </div>
    </div>
</div>
<br>
<div class="col-lg-10 text-center">
   {!! link_to(URL::previous(),'Back', ['class' => 'btn btn-warning btn-md']) !!}
   {{ Form::submit('Update', ['class' => 'btn btn-primary']) }}
</div>
{!! Form::close() !!}
public function update(Request $request, $id)
{
    $valueitemregistrations = Itemregistration::find($id);

    $this->validate($request,['gambar' => 'max:100000',]);
    if ($request->hasFile('gambar')) {
        // Get the file from the request
        $file = $request->file('gambar');
        // Get the contents of the file
        $content = $file->openFile()->fread($file->getSize());

        $valueitemregistrations->Picture = $content;
        $valueitemregistrations->update();

        if($valueitemregistrations) {
            return redirect('profil');
        } else {
            return redirect()->back()->withInput();
        }
    } else { 
        echo "testing";
    }
}
当我尝试上传和更新时,会转到echo“testing”。它未检测到任何上载的文件

我一直在为add.blade使用相同的代码,它可以正常工作


它是否与路由路径相关?

当HTML表单没有
enctype=“multipart/form data”
时,会发生这种情况

在这种情况下,原因是
'files'=>true
表单::model()
中错误数组的一部分;当它应该在外部时,它在
'action'
数组中。试试这个:

Form::model($dataItemregistration[
'方法'=>'补丁',
'动作'=>['模块\ProfilController@update“,$dataItemregistration->ItemRegistrationID],
“文件”=>true,
]);

你真棒..我已经试了好几天找到问题..谢谢你的时间和帮助。。。我已经接受了你的回答。