php - 从 View 中的表单读取文件输入时总是出错

标签 php forms laravel upload

在那里我使用了两个输入文件,一个是隐藏的,一个是可见的,这里我想尝试如何调用 Controller 的输入,但是有一个错误Call to a member function getRealPath() on null ,如何调用隐藏在表单中的输入文件。谢谢你的回答

在 Controller 脚本中:

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 :

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

最佳答案

它不适用于 GET 方法:

method="GET"

您应该为 POST 更改它。您的路线还:

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

关于php - 从 View 中的表单读取文件输入时总是出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39484707/

相关文章:

php - 我的登录脚本在本地服务器上工作正常,但在实时服务器上无法工作

php - '<?=' 在 PHP 中是什么意思?

JavaScript/jQuery : Get the changed content of textarea

javascript - 循环遍历多个表单并循环遍历每个表单元素并收集它们的属性

laravel - 使用 VueJS、axios 和 Laravel 上传文件

php - 带有重音字符的列

javascript - 在 HTML 选择中复制数据(选项)

javascript - 发送联系表格后的电子邮件无效

mysql - Eloquent 嵌套关系

php - 根据其他循环数据显示循环数据 laravel