【问题标题】:Laravel File Uploads Error: Missing a temporary folderLaravel 文件上传错误:缺少临时文件夹
【发布时间】:2018-04-24 17:39:09
【问题描述】:

我正在使用 Ubuntu 16.04、ISPConfig 和 Laravel 运行服务器。对于测试,我得到了一个具有基本相同设置的本地测试服务器。测试服务器有另一个域,没有 https。我已经在我的测试服务器上集成了 Laravel 的文件上传。我使用http://image.intervention.io/,它在我的测试服务器上运行良好。

Liveserver 失败。无法传递“hasFile”函数。

表格:

<div class="form-group">
  <div class="row">
    <div class="col-md-10 col-md-offset-1">
      <img src="/uploads/avatars/{{$user->avatar}}" style="width:150px; 
       height:150px; float:left; border-radius:50%; margin-
       right:25px;">
      <form enctype="multipart/form-data" 
       action="/account/edit/upload_avatar" method="post">
        <input type="file" name="avatar">
        {{ csrf_field() }}
        <input type="submit" class="pull-right btn btn-sm btn-primary">
      </form>
    </div>
  </div>
</div>

控制器:

 public function upload_avatar(Request $request)
 {
    dd($request);

    if($request->hasFile('avatar')) {
      $avatar = $request->file('avatar');
      $filename = time() . '.' . $avatar->getClientOriginalExtension();
      Image::make($avatar)->resize(300, 300)->save( 
      public_path('uploads/avatars/' . $filename));

      $user = Sentinel::getUser();
      $user->avatar = $filename;
      $user->save();

      return back();
    }
  }

请求:

Request {#39 ▼
#json: null
#convertedFiles: null
#userResolver: Closure {#330 ▶}
#routeResolver: Closure {#322 ▶}
+attributes: ParameterBag {#41 ▶}
+request: ParameterBag {#40 ▶}
+query: ParameterBag {#47 ▶}
+server: ServerBag {#44 ▶}
+files: FileBag {#43 ▼
#parameters: array:1 [▼
  "avatar" => UploadedFile {#28 ▼
    -test: false
    -originalName: "2.jpg"
    -mimeType: "application/octet-stream"
    -size: 0
    -error: 6
    path: ""
    filename: ""
    basename: ""
    pathname: ""
    extension: ""
    realPath: "/var/www/clients/client1/web1/web/public"
    aTime: 1970-01-01 00:00:00
    mTime: 1970-01-01 00:00:00
    cTime: 1970-01-01 00:00:00
    inode: false
    size: false
    perms: 00
    owner: false
    group: false
    type: false
    writable: false
    readable: false
    executable: false
    file: false
    dir: false
    link: false
      }
    ]
  }
  +cookies: ParameterBag {#42 ▶}
  +headers: HeaderBag {#45 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/account/edit/upload_avatar"
  #requestUri: "/account/edit/upload_avatar"
  #baseUrl: ""
  #basePath: null
  #method: "POST"
  #format: null
  #session: Store {#375 ▶}
  #locale: null
  #defaultLocale: "en"
  -isHostValid: true
  -isClientIpsValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
  }

错误:6 UPLOAD_ERR_NO_TMP_DIR

值:6;缺少一个临时文件夹。在 PHP 4.3.10 和 PHP 中引入

Php.ini 的文件上传设置与测试服务器相同。 这是来自我的 php.ini:

    ;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default 
 if not
; specified).
; http://php.net/upload-tmp-dir
;upload_tmp_dir =

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 2M

; Maximum number of files that can be uploaded via a single request
max_file_uploads = 20

没有 if(hasFile) iIget 如下:

NotReadableException
Unsupported image type. GD driver is only able to decode JPG, PNG, GIF 
or WebP files.

我已经检查了整个项目的文件权限,甚至在文件目标上使用 777 进行了尝试。

【问题讨论】:

  • 尝试在 php.ini 中更新 upload_tmp_dir=""
  • 还是一样。
  • 修改php.ini后需要重启服务器

标签: laravel ubuntu upload intervention


【解决方案1】:

我知道了,谢谢!现在解决了。 Tmp 文件夹手错权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-16
    • 2020-01-07
    • 2021-07-19
    • 1970-01-01
    • 2018-07-15
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多