【问题标题】:Input::file empty输入::文件为空
【发布时间】:2016-08-10 07:29:57
【问题描述】:

我正在尝试上传文件,它会这样做:

HTML:

{!!Form::open(['route'=>'radicado.update','method'=>'PUT', 'action' => 'RadicadoController@update', 'id' => 'radicado' , 'files' => true])!!}   


{!!Form::file('archivoNuevaVersion', ['id'=>'archivoNuevaVersion']) !!}

在控制器上:

$file = Input::file('archivoNuevaVersion');
if ($file != '') 
    {
        $ruta = public_path() . '/repositorio/'.$carpeta['directorioSerie']."/".$carpeta['directorioSubSerie']."/".$carpeta['directorioDocumento']."/";
        $filename = $file->getClientOriginalName();    
        $destinationPath = $ruta.$filename;
    }
    else
    {
        echo "Upload file";
    }

但条件总是在 else 上。 将文件上传到 laravel 的正确方法是什么?

【问题讨论】:

    标签: laravel file-upload upload


    【解决方案1】:

    表单仅支持 GET 和 POST 方法,不支持 PUT。

    {!!Form::open(['route'=>'radicado.update','method'=>'POST', 'action' => 'RadicadoController@update', 'id' => 'radicado' , 'files' => true])!!}
    
    {!!Form::file('archivoNuevaVersion', ['id'=>'archivoNuevaVersion']) !!}
    

    您应该如下修改控制器:

    if (Input::hasFile('archivoNuevaVersion')) 
    {
        $file = Input::file('archivoNuevaVersion');
        $ruta = public_path() . '/repositorio/'.$carpeta['directorioSerie']."/".$carpeta['directorioSubSerie']."/".$carpeta['directorioDocumento']."/";
        $filename = $file->getClientOriginalName();    
        $destinationPath = $ruta.$filename;
    }
    else
    {
        echo "Upload file";
    }
    

    【讨论】:

    • 我已经尝试过并告诉我:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException。路由会是什么,还是应该是?
    • 张贴你的 routes.php 为你试图命中的控制器。
    • 这是:Route::post('update','RadicadoController@update');
    • 在将相关路由从put 更新为post 后,您应该不会收到MethodNotAllowedHttpException。如果仍然有错误,现在显示的错误消息是什么?
    • 我仍然遇到同样的错误:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException。
    【解决方案2】:

    您的 php.ini 配置似乎有问题。尝试更新以下变量。

    upload_max_filesize=1G
    post_max_size=2G
    memory_limit = 3G
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      • 2016-05-13
      • 2019-02-08
      • 2015-11-16
      相关资源
      最近更新 更多