切换导航条
此项目
正在载入...
登录
何书鹏
/
salarycalculator
·
提交
转到一个项目
GitLab
转到仪表盘
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
Karson
4 years ago
提交
dd83a6255e95e0a2efd21a975949e3ce1800718e
1 个父辈
260198e1
修复分片上传在Windows下的兼容问题
优化分片上传合并失败时清除分片文件
隐藏空白字符变更
内嵌
并排对比
正在显示
1 个修改的文件
包含
32 行增加
和
7 行删除
application/common/library/Upload.php
application/common/library/Upload.php
查看文件 @
dd83a62
...
...
@@ -28,6 +28,8 @@ class Upload
*/
protected
static
$maxCheckNums
=
10
;
protected
$merging
=
false
;
protected
$chunkDir
=
null
;
protected
$config
=
[];
...
...
@@ -171,7 +173,11 @@ class Upload
{
$iterator
=
new
\GlobIterator
(
$this
->
chunkDir
.
DS
.
$chunkid
.
'-*'
,
FilesystemIterator
::
KEY_AS_FILENAME
);
$array
=
iterator_to_array
(
$iterator
);
var_dump
(
$array
);
foreach
(
$array
as
$index
=>
&
$item
)
{
$sourceFile
=
$item
->
getRealPath
()
?:
$item
->
getPathname
();
$item
=
null
;
@
unlink
(
$sourceFile
);
}
}
/**
...
...
@@ -195,6 +201,7 @@ class Upload
}
}
if
(
!
$completed
)
{
$this
->
clean
(
$chunkid
);
throw
new
UploadException
(
__
(
'Chunk file info error'
));
}
...
...
@@ -202,6 +209,7 @@ class Upload
$uploadPath
=
$filePath
;
if
(
!
$destFile
=
@
fopen
(
$uploadPath
,
"wb"
))
{
$this
->
clean
(
$chunkid
);
throw
new
UploadException
(
__
(
'Chunk file merge error'
));
}
if
(
flock
(
$destFile
,
LOCK_EX
))
{
// 进行排他型锁定
...
...
@@ -229,12 +237,15 @@ class Upload
'error'
=>
0
,
'size'
=>
$file
->
getSize
()
];
$file
->
setUploadInfo
(
$info
);
$file
->
set
SaveName
(
$filename
)
->
set
UploadInfo
(
$info
);
$file
->
isTest
(
true
);
//重新设置文件
$this
->
setFile
(
$file
);
unset
(
$file
);
$this
->
merging
=
true
;
//允许大文件
$this
->
config
[
'maxsize'
]
=
"1024G"
;
...
...
@@ -287,14 +298,28 @@ class Upload
$uploadDir
=
substr
(
$savekey
,
0
,
strripos
(
$savekey
,
'/'
)
+
1
);
$fileName
=
substr
(
$savekey
,
strripos
(
$savekey
,
'/'
)
+
1
);
$destDir
=
ROOT_PATH
.
'public'
.
$uploadDir
;
$destDir
=
ROOT_PATH
.
'public'
.
str_replace
(
'/'
,
DS
,
$uploadDir
)
;
$sha1
=
$this
->
file
->
hash
();
$file
=
$this
->
file
->
move
(
$destDir
,
$fileName
);
if
(
!
$file
)
{
// 上传失败获取错误信息
throw
new
UploadException
(
$this
->
file
->
getError
());
//如果是合并文件
if
(
$this
->
merging
)
{
if
(
!
$this
->
file
->
check
())
{
throw
new
UploadException
(
$this
->
file
->
getError
());
}
$destFile
=
$destDir
.
$fileName
;
$sourceFile
=
$this
->
file
->
getRealPath
()
?:
$this
->
file
->
getPathname
();
$info
=
$this
->
file
->
getInfo
();
$this
->
file
=
null
;
rename
(
$sourceFile
,
$destFile
);
$file
=
new
File
(
$destFile
);
$file
->
setSaveName
(
$fileName
)
->
setUploadInfo
(
$info
);
}
else
{
$file
=
$this
->
file
->
move
(
$destDir
,
$fileName
);
if
(
!
$file
)
{
// 上传失败获取错误信息
throw
new
UploadException
(
$this
->
file
->
getError
());
}
}
$this
->
file
=
$file
;
$params
=
array
(
...
...
请
注册
或
登录
后发表评论