Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
2d85ef0e
Commit
2d85ef0e
authored
12 years ago
by
Bart Visscher
Browse files
Options
Downloads
Patches
Plain Diff
Chunked upload: Refactor to static class
parent
a7a54331
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/connector/sabre/directory.php
+5
-18
5 additions, 18 deletions
lib/connector/sabre/directory.php
lib/filechunking.php
+53
-0
53 additions, 0 deletions
lib/filechunking.php
with
58 additions
and
18 deletions
lib/connector/sabre/directory.php
+
5
−
18
View file @
2d85ef0e
...
...
@@ -49,25 +49,12 @@ class OC_Connector_Sabre_Directory extends OC_Connector_Sabre_Node implements Sa
*/
public
function
createFile
(
$name
,
$data
=
null
)
{
if
(
isset
(
$_SERVER
[
'HTTP_OC_CHUNKED'
]))
{
$cache
=
new
OC_Cache_File
();
$cache
->
set
(
$name
,
$data
);
preg_match
(
'/(?P<name>.*)-chunking-(?P<transferid>\d+)-(?P<chunkcount>\d+)-(?P<index>\d+)/'
,
$name
,
$matches
);
$prefix
=
$matches
[
'name'
]
.
'-chunking-'
.
$matches
[
'transferid'
]
.
'-'
.
$matches
[
'chunkcount'
]
.
'-'
;
$parts
=
0
;
for
(
$i
=
0
;
$i
<
$matches
[
'chunkcount'
];
$i
++
)
{
if
(
$cache
->
hasKey
(
$prefix
.
$i
))
{
$parts
++
;
}
}
if
(
$parts
==
$matches
[
'chunkcount'
])
{
$newPath
=
$this
->
path
.
'/'
.
$matches
[
'name'
];
OC_FileChunking
::
store
(
$name
,
$data
);
$info
=
OC_FileChunking
::
decodeName
(
$name
);
if
(
OC_FileChunking
::
isComplete
(
$info
))
{
$newPath
=
$this
->
path
.
'/'
.
$info
[
'name'
];
$f
=
OC_Filesystem
::
fopen
(
$newPath
,
'w'
);
for
(
$i
=
0
;
$i
<
$matches
[
'chunkcount'
];
$i
++
)
{
$chunk
=
$cache
->
get
(
$prefix
.
$i
);
$cache
->
remove
(
$prefix
.
$i
);
fwrite
(
$f
,
$chunk
);
}
fclose
(
$f
);
OC_FileChunking
::
assemble
(
$info
,
$f
);
return
OC_Connector_Sabre_Node
::
getETagPropertyForPath
(
$newPath
);
}
}
else
{
...
...
This diff is collapsed.
Click to expand it.
lib/filechunking.php
0 → 100644
+
53
−
0
View file @
2d85ef0e
<?php
/**
* Copyright (c) 2012 Bart Visscher <bartv@thisnet.nl>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
class
OC_FileChunking
{
static
public
function
decodeName
(
$name
)
{
preg_match
(
'/(?P<name>.*)-chunking-(?P<transferid>\d+)-(?P<chunkcount>\d+)-(?P<index>\d+)/'
,
$name
,
$matches
);
return
$matches
;
}
static
public
function
getPrefix
(
$name
,
$transferid
,
$chunkcount
)
{
return
$name
.
'-chunking-'
.
$transferid
.
'-'
.
$chunkcount
.
'-'
;
}
static
public
function
store
(
$name
,
$data
)
{
$cache
=
new
OC_Cache_File
();
$cache
->
set
(
$name
,
$data
);
}
static
public
function
isComplete
(
$info
)
{
$prefix
=
OC_FileChunking
::
getPrefix
(
$info
[
'name'
],
$info
[
'transferid'
],
$info
[
'chunkcount'
]
);
$parts
=
0
;
$cache
=
new
OC_Cache_File
();
for
(
$i
=
0
;
$i
<
$info
[
'chunkcount'
];
$i
++
)
{
if
(
$cache
->
hasKey
(
$prefix
.
$i
))
{
$parts
++
;
}
}
return
$parts
==
$info
[
'chunkcount'
];
}
static
public
function
assemble
(
$info
,
$f
)
{
$cache
=
new
OC_Cache_File
();
$prefix
=
OC_FileChunking
::
getPrefix
(
$info
[
'name'
],
$info
[
'transferid'
],
$info
[
'chunkcount'
]
);
for
(
$i
=
0
;
$i
<
$info
[
'chunkcount'
];
$i
++
)
{
$chunk
=
$cache
->
get
(
$prefix
.
$i
);
$cache
->
remove
(
$prefix
.
$i
);
fwrite
(
$f
,
$chunk
);
}
fclose
(
$f
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment