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
ea80a8b9
Commit
ea80a8b9
authored
12 years ago
by
Thomas Müller
Browse files
Options
Downloads
Plain Diff
Merge pull request #114 from riso/xsendfile
Implement X-Sendfile support
parents
e28d71bf
de7e4196
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cron.php
+3
-0
3 additions, 0 deletions
cron.php
lib/files.php
+33
-4
33 additions, 4 deletions
lib/files.php
lib/helper.php
+31
-0
31 additions, 0 deletions
lib/helper.php
with
67 additions
and
4 deletions
cron.php
+
3
−
0
View file @
ea80a8b9
...
...
@@ -56,6 +56,9 @@ if( !OC_Config::getValue( 'installed', false )) {
// Handle unexpected errors
register_shutdown_function
(
'handleUnexpectedShutdown'
);
// Delete temp folder
OC_Helper
::
cleanTmpNoClean
();
// Exit if background jobs are disabled!
$appmode
=
OC_BackgroundJob
::
getExecutionType
();
if
(
$appmode
==
'none'
)
{
...
...
This diff is collapsed.
Click to expand it.
lib/files.php
+
33
−
4
View file @
ea80a8b9
...
...
@@ -140,6 +140,11 @@ class OC_Files {
* @param boolean $only_header ; boolean to only send header of the request
*/
public
static
function
get
(
$dir
,
$files
,
$only_header
=
false
)
{
$xsendfile
=
false
;
if
(
isset
(
$_SERVER
[
'MOD_X_SENDFILE_ENABLED'
])
||
isset
(
$_SERVER
[
'MOD_X_ACCEL_REDIRECT_ENABLED'
]))
{
$xsendfile
=
true
;
}
if
(
strpos
(
$files
,
';'
))
{
$files
=
explode
(
';'
,
$files
);
}
...
...
@@ -149,7 +154,11 @@ class OC_Files {
$executionTime
=
intval
(
ini_get
(
'max_execution_time'
));
set_time_limit
(
0
);
$zip
=
new
ZipArchive
();
$filename
=
OC_Helper
::
tmpFile
(
'.zip'
);
if
(
$xsendfile
)
{
$filename
=
OC_Helper
::
tmpFileNoClean
(
'.zip'
);
}
else
{
$filename
=
OC_Helper
::
tmpFile
(
'.zip'
);
}
if
(
$zip
->
open
(
$filename
,
ZIPARCHIVE
::
CREATE
|
ZIPARCHIVE
::
OVERWRITE
)
!==
true
)
{
exit
(
"cannot open <
$filename
>
\n
"
);
}
...
...
@@ -170,7 +179,11 @@ class OC_Files {
$executionTime
=
intval
(
ini_get
(
'max_execution_time'
));
set_time_limit
(
0
);
$zip
=
new
ZipArchive
();
$filename
=
OC_Helper
::
tmpFile
(
'.zip'
);
if
(
$xsendfile
)
{
$filename
=
OC_Helper
::
tmpFileNoClean
(
'.zip'
);
}
else
{
$filename
=
OC_Helper
::
tmpFile
(
'.zip'
);
}
if
(
$zip
->
open
(
$filename
,
ZIPARCHIVE
::
CREATE
|
ZIPARCHIVE
::
OVERWRITE
)
!==
true
)
{
exit
(
"cannot open <
$filename
>
\n
"
);
}
...
...
@@ -191,8 +204,13 @@ class OC_Files {
ini_set
(
'zlib.output_compression'
,
'off'
);
header
(
'Content-Type: application/zip'
);
header
(
'Content-Length: '
.
filesize
(
$filename
));
self
::
addSendfileHeader
(
$filename
);
}
else
{
header
(
'Content-Type: '
.
OC_Filesystem
::
getMimeType
(
$filename
));
$storage
=
OC_Filesystem
::
getStorage
(
$filename
);
if
(
$storage
instanceof
OC_Filestorage_Local
)
{
self
::
addSendfileHeader
(
OC_Filesystem
::
getLocalFile
(
$filename
));
}
}
}
elseif
(
$zip
or
!
OC_Filesystem
::
file_exists
(
$filename
))
{
header
(
"HTTP/1.0 404 Not Found"
);
...
...
@@ -217,7 +235,9 @@ class OC_Files {
flush
();
}
}
unlink
(
$filename
);
if
(
!
$xsendfile
)
{
unlink
(
$filename
);
}
}
else
{
OC_Filesystem
::
readfile
(
$filename
);
}
...
...
@@ -228,11 +248,20 @@ class OC_Files {
}
}
private
static
function
addSendfileHeader
(
$filename
)
{
if
(
isset
(
$_SERVER
[
'MOD_X_SENDFILE_ENABLED'
]))
{
header
(
"X-Sendfile: "
.
$filename
);
}
if
(
isset
(
$_SERVER
[
'MOD_X_ACCEL_REDIRECT_ENABLED'
]))
{
header
(
"X-Accel-Redirect: "
.
$filename
);
}
}
public
static
function
zipAddDir
(
$dir
,
$zip
,
$internalDir
=
''
)
{
$dirname
=
basename
(
$dir
);
$zip
->
addEmptyDir
(
$internalDir
.
$dirname
);
$internalDir
.
=
$dirname
.
=
'/'
;
$files
=
OC_Files
::
get
d
irectory
c
ontent
(
$dir
);
$files
=
OC_Files
::
get
D
irectory
C
ontent
(
$dir
);
foreach
(
$files
as
$file
)
{
$filename
=
$file
[
'name'
];
$file
=
$dir
.
'/'
.
$filename
;
...
...
This diff is collapsed.
Click to expand it.
lib/helper.php
+
31
−
0
View file @
ea80a8b9
...
...
@@ -524,6 +524,27 @@ class OC_Helper {
return
$file
;
}
/**
* create a temporary file with an unique filename. It will not be deleted
* automatically
* @param string $postfix
* @return string
*
*/
public
static
function
tmpFileNoClean
(
$postfix
=
''
)
{
$tmpDirNoClean
=
get_temp_dir
()
.
'/oc-noclean/'
;
if
(
!
file_exists
(
$tmpDirNoClean
)
||
!
is_dir
(
$tmpDirNoClean
))
{
if
(
file_exists
(
$tmpDirNoClean
))
{
unlink
(
$tmpDirNoClean
);
}
mkdir
(
$tmpDirNoClean
);
}
$file
=
$tmpDirNoClean
.
md5
(
time
()
.
rand
())
.
$postfix
;
$fh
=
fopen
(
$file
,
'w'
);
fclose
(
$fh
);
return
$file
;
}
/**
* create a temporary folder with an unique filename
* @return string
...
...
@@ -559,6 +580,16 @@ class OC_Helper {
}
}
/**
* remove all files created by self::tmpFileNoClean
*/
public
static
function
cleanTmpNoClean
()
{
$tmpDirNoCleanFile
=
get_temp_dir
()
.
'/oc-noclean/'
;
if
(
file_exists
(
$tmpDirNoCleanFile
))
{
self
::
rmdirr
(
$tmpDirNoCleanFile
);
}
}
/**
* Adds a suffix to the name in case the file exists
*
...
...
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