我正在使用Ubuntu 16.04,ISPConfig和Laravel运行服务器。对于测试,我得到了一个基本相同设置的本地Testserver。 Testserver有另一个域,没有https。我在我的Testserver上集成了Laravel的文件上传。我使用http://image.intervention.io/,它在我的Testserver上工作正常。
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与Testserver具有相同的文件上传设置。 这是我的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),请输入以下内容:
NotReadableException
Unsupported image type. GD driver is only able to decode JPG, PNG, GIF
or WebP files.
我已经检查了整个项目的文件权限,甚至在文件目的地上使用777进行了尝试。
答案 0 :(得分:0)
我知道,谢谢!现在解决了。 Tmp文件夹手权限错误。