首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >文件类型post返回文件大小为零,以laravel 5表示。

文件类型post返回文件大小为零,以laravel 5表示。
EN

Stack Overflow用户
提问于 2019-07-10 07:39:49
回答 2查看 1.5K关注 0票数 0

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

我正在将图像保存在/storage上,它已经损坏了,如何修复它?

代码语言:javascript
复制
   //this is the controller

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

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

代码语言:javascript
复制
"image_path" => UploadedFile {#30 ▼-originalName: "Tulips.jpg"mimeType:"application/octet-stream"-size: 0-error: 6

//这是带有刀片形状的视图

代码语言:javascript
复制
{!! 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表单

代码语言:javascript
复制
<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" />
EN

回答 2

Stack Overflow用户

发布于 2019-07-10 07:54:00

getClientSize()在Laravel不受欢迎。使用$request->file('image_path')->getSize()

正如它在Laravel来源中提到的那样。

代码语言:javascript
复制
 /**
     * 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();
    }
票数 0
EN

Stack Overflow用户

发布于 2019-07-11 01:09:16

我已经确定了问题所在,在IIS中,version.It被设置为php7.2,在我将它更改为php5.5之后,它就工作了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56965682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档