laravel 5中文件类型后返回文件大小为零

时间:2019-07-10 07:39:49

标签: laravel laravel-5

这是场景 我正在上传858 KB文件 但在Controller中为0kb 当我保存在storage_path()中时,它是空的

我正在将映像保存在/ storage上,它已损坏 我该如何解决

   //this is the controller

   $input = $request->all();
   echo  $request->file('image_path')->getClientSize();
   dd($input);
  

**这是dd的返回值**           0


"image_path" => UploadedFile {#30 ▼-originalName: "Tulips.jpg"mimeType:"application/octet-stream"-size: 0-error: 6

//这是刀片形式的视图

{!! Form::open(array('url' => 'test2', 'files'=> true)) !!}
                            <div class="form-group">
                                {!! Form::text('title',Input::old('title'),['class'=>'form-control', 'placeholder' => 'What is your title?']) !!}
                            </div>
                            <div class="form-group">
                                {!! Form::label('image', 'Your Image') !!}
                                {!! Form::file('image_path') !!}
                                <p class="help-block">Hey! Please don't upload over 15MB images!</p>
                            </div>
                            <div class="form-group">
                                {!! Form::label('caption', 'Don\'t miss to caption!') !!}
                                {!! Form::text('caption',Input::old('caption'),['class'=>'form-control', 'placeholder' => 'Your caption']) !!}
                            </div>
                            {!! Form::submit('Post  now!',['class'=>'btn btn-info']) !!}
                            {!!Form::close() !!}

//我也尝试html表单

<form id="pdf" action="{{ route('test2') }}" method="POST"enctype="multipart/form-data">
<input type="file" name="image_path">
<span id="imgName">Choose a File</span>
<input type="text" name="_token" value=" 
    {{csrf_token()}}">
<input type="file" name="image_path" 
      id="path" />
<input type="submit" />

2 个答案:

答案 0 :(得分:0)

getClientSize()在Laravel中已弃用。使用$request->file('image_path')->getSize();

如Laravel资料中所述。

 /**
     * Returns the file size.
     *
     * It is extracted from the request from which the file has been uploaded.
     * Then it should not be considered as a safe value.
     *
     * @deprecated since Symfony 4.1, use getSize() instead.
     *
     * @return int|null The file sizes
     */
    public function getClientSize()
    {
        @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1. Use getSize() instead.', __METHOD__), E_USER_DEPRECATED);

        return $this->getSize();
    }

答案 1 :(得分:0)

我已经确定了问题所在,并且是IIS php版本。在将其更改为php 5.5后它可以设置为php 7.2