【问题标题】:Laravel 4.2 + nginx return Input::file nullLaravel 4.2 + nginx 返回 Input::file null
【发布时间】:2015-04-07 16:01:07
【问题描述】:

我的处境很奇怪:

当我尝试使用 Form::file('image') 上传一些文件时,我只得到空值。

表格

{{ Form::open(['route' => 'admin.companies.store', 'class' => 'form', 'files' => true]) }}

<h3>{{ trans('messages.companies.data_company') }}</h3>

<div class="form-group">
    {{ Form::label('image', trans('messages.companies.image')) }}
    <div class="row">
        <div class="col-xs-4">
            {{ Form::file('image') }}
            @include ('partials.validator_field', ['field' => 'image'])
        </div>
    </div>
</div>

nginx

首先我尝试验证我的 nginx 配置,但显然没问题。

server {
    listen 80;
    server_name www.example.com.build example.com.build;
    access_log /var/www/customers/example/logs/access.log;
    error_log /var/www/customers/example/logs/error.log;
    root /var/www/customers/example/example/public;

    client_max_body_size 100m;

    location / {
        sendfile on;
        client_max_body_size 200m;
        try_files $uri $uri/ /index.php$is_args$args;
        index  index.html index.htm index.php;
    }

    location ~ \.php$ {
        include /usr/local/etc/nginx/fastcgi_params;
        try_files $uri /index.php =404;
        fastcgi_index index.php;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /var/www/customers/example/example/public$fastcgi_script_name;
        fastcgi_param debug true;
    }
}

权限

然后我尝试将777权限授予app/storagepublic/imagespublic/upload(我正在使用intervention/image上传包):同样的错误,没什么变化。


奇怪的测试

我测试了一个像&lt;input type="file" name="teste /&gt; 这样的“纯输入文件”,上传成功:PHP 已收到图像。


最终输出(var_dump)

$_FILES

array(1) {
  ["image"]=>
  array(5) {
    ["name"]=>
    string(0) ""
    ["type"]=>
    string(0) ""
    ["tmp_name"]=>
    string(0) ""
    ["error"]=>
    int(4)
    ["size"]=>
    int(0)
  }
}
Input::file('image')

NULL
Input::all()

array(31) {
  ["_token"]=>
  string(40) "GDaT0jqKmpmDyGw4BeRVW1tCb01T1ni5gvKoKCPg"
  ["name"]=>
  string(4) "tste"
  ["description"]=>
  string(0) ""
  ["corporate_name"]=>
  string(0) ""
  ["company_segment_id"]=>
  string(1) "4"
  ["company_relationship_id"]=>
  string(1) "2"
  ["contract"]=>
  string(0) ""
  ["state_registration"]=>
  string(0) ""
  ["cnpj"]=>
  string(0) ""
  ["cnae_session"]=>
  string(0) ""
  ["address"]=>
  string(0) ""
  ["street"]=>
  string(0) ""
  ["street_number"]=>
  string(0) ""
  ["street_complement"]=>
  string(0) ""
  ["postalcode"]=>
  string(0) ""
  ["neighborhood"]=>
  string(0) ""
  ["state_id"]=>
  string(1) "1"
  ["city_id"]=>
  string(0) ""
  ["landmark"]=>
  string(0) ""
  ["phone_comercial"]=>
  string(0) ""
  ["phone_fax"]=>
  string(0) ""
  ["phone_mobile_1"]=>
  string(0) ""
  ["phone_mobile_2"]=>
  string(0) ""
  ["site"]=>
  string(0) ""
  ["skype"]=>
  string(0) ""
  ["facebook"]=>
  string(0) ""
  ["linkedin"]=>
  string(0) ""
  ["youtube_channel"]=>
  string(0) ""
  ["informations"]=>
  string(0) ""
  ["active"]=>
  string(2) "on"
  ["image"]=>
  NULL
}

信息

Nginx 版本:nginx/1.6.2

PHP 5.6.6 (cli)(构建时间:2015 年 3 月 9 日 00:40:37) 版权所有 (c) 1997-2015 PHP 集团 Zend Engine v2.6.0,版权所有 (c) 1998-2015 Zend Technologies

Mac OS 优胜美地


这是我第一个使用 nginx 的项目。

对不起我的英语。

【问题讨论】:

    标签: php macos laravel nginx intervention


    【解决方案1】:

    你可以试试去掉这部分吗:

    @include ('partials.validator_field', ['field' => 'image'])
    

    您已经打开了一个图像输入。这部分是干什么用的?

    【讨论】:

    • 这只是部分显示错误。仅此而已。
    • 出现这个问题是因为我有2个同名字段:初级问题哈哈。
    • 在@include ('partials.validator_field', ['field' => 'image']) 中也是这样吗?
    【解决方案2】:

    检查该表单的所有字段,我发现另一个具有相同名称的字段。

    新手问题。

    谢谢大家。

    【讨论】:

      猜你喜欢
      • 2016-10-09
      • 2016-11-08
      • 2014-11-09
      • 1970-01-01
      • 1970-01-01
      • 2018-04-21
      • 2014-04-26
      • 1970-01-01
      • 2022-01-27
      相关资源
      最近更新 更多