【问题标题】:Uploaded file not available for processing?上传的文件无法处理?
【发布时间】:2014-02-15 20:17:55
【问题描述】:

问题:

当我选择文件并提交表单时,它会进入处理页面,但显然不发送文件数组,只是文件名。

目标:

接受并上传文件到适当的目录。


环境:

  • 本地
  • OSX / MAMP Pro
  • PHP / Laravel 4

上传控制器:

public function uploadLogo() {
    $locals['route'] = route('saveProfileLogo');
    return View::make('upload_file', $locals);
}

上传视图:

<form method="get" action="{{{$route}}}" enctype="multipart/form-data" class="grid-form">
    <label>File</label>
    <input type="file" name="fresh_file" />

    <input type="submit" class="btn btn-primary" value="Start Upload" />
</form>

保存控制器:

public function saveLogo() {
    // Always fails
    // if (!Input::hasFile('fresh_file'))
        // return 'No file provided.';

    // Always shows: array(1) { ["fresh_file"]=> string(21) "Angular Mountains.jpg" }
    // dd(Input::all());

    Input::file('fresh_file')->move(public_path() . '/files');
    return View::make('upload_file_response');
}

【问题讨论】:

  • 我的猜测是你不必将 "public_path() . " 添加到 "Input::file('fresh_file')->move('/files');
  • 我尝试了您的建议,但无济于事。

标签: php laravel-4 mamp


【解决方案1】:

您应该在表单中使用method="post",而不是get,这就是您将文件视为字符串的原因。

【讨论】:

    猜你喜欢
    • 2021-12-23
    • 2012-04-06
    • 2017-12-30
    • 2011-07-12
    • 2013-11-15
    • 2019-01-04
    • 1970-01-01
    • 2021-02-20
    • 2015-03-13
    相关资源
    最近更新 更多