PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-从视图中的表单读取文件输入时始终出现错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

在这里我使用两个输入文件,一个隐藏并且一个可见,在这里我想尝试如何将输入调用到控制器,但是有一个错误,在Null上调用成员函数getRealPath(),如何调用输入文件隐藏在表单中.感谢您的回答

在控制器脚本中:

public function postPhoto()
    {
        $photo = Input::file('photo')->getRealPath();

        if($this->cekUkuranFoto($photo) == falsE)
        {
            Session::flash('message', 'size too big 2048 x 2048 !');
            return redirect()->BACk();
        }
}
public function cekUkuranFoto($filE)
    {
        $gambar = Image::make($filE);
        $ukuran = getimagesize($filE);
        $width=$ukuran[0];
        $height=$ukuran[1];

        if($width < 2048 && height < 2048)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

在此查看表格:

<form method="GET" action="{!! URL::to('/timeline/photo') !!}" files="true" enctype="multipart/form-data">
                <div class="Box-body">
                  <div class="form-group">
                  <input name='photo' id="file-image" type='file' onchange="readURL(this);" style="visibility:hidden;"/>
                    <p class="Help-block">Maksimal ukuran foto 1500 x 1000 pixel</p>
                  <div class="col-sm-6">
                    <img id="image-responsive" class="img-responsive img-bordered-sm" src="{!! url('/').'/protected/public/assets/images/default.png' !!}" height=128 alt="your image"/><br/>
                    <input name="photo2" type="button" id="my-button" class ="btn btn-info" accept=".jpg,.jpeg,.png" value="Pilih Foto">
                    <button type="button" class="btn btn-danger" onclick="hapusGambar()" >Hapus</button>
                  </div>
                  <div class="col-sm-6">
                  <textarea name="photoinput" class="form-control" rows="6" placeholder="Deskripsi">{!! Input::old('photoinput') !!}</textarea>
                  </div>
                </div>
                </div>
                <div class="Box-footer">
                  <button type="submit" class="btn btn-info pull-right">PosTing</button>
                </div>
                </form>

在途中:

Route::get('/timeline/photo', 'ClientTimeLineContr@postPhoto' );

解决方法:

不适用于GET方法

@H_788_6@method="GET"

您应该将其更改为POST.您的路线还:

Route::post('/timeline/photo', 'ClientTimeLineContr@postPhoto' );

大佬总结

以上是大佬教程为你收集整理的php-从视图中的表单读取文件输入时始终出现错误全部内容,希望文章能够帮你解决php-从视图中的表单读取文件输入时始终出现错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: