Skip to content
Snippets Groups Projects
Commit 71f17ac4 authored by Andreas Gohr's avatar Andreas Gohr
Browse files

copy not move uploaded files FS#2465

This fixes problems with setgid bits on the media directory
parent fa446926
No related branches found
No related tags found
No related merge requests found
...@@ -296,7 +296,7 @@ function media_upload($ns,$auth,$file=false){ ...@@ -296,7 +296,7 @@ function media_upload($ns,$auth,$file=false){
$res = media_save(array('name' => $file['tmp_name'], $res = media_save(array('name' => $file['tmp_name'],
'mime' => $imime, 'mime' => $imime,
'ext' => $iext), $ns.':'.$id, 'ext' => $iext), $ns.':'.$id,
$INPUT->post->bool('ow'), $auth, 'move_uploaded_file'); $INPUT->post->bool('ow'), $auth, 'copy_uploaded_file');
if (is_array($res)) { if (is_array($res)) {
msg($res[0], $res[1]); msg($res[0], $res[1]);
return false; return false;
...@@ -304,6 +304,23 @@ function media_upload($ns,$auth,$file=false){ ...@@ -304,6 +304,23 @@ function media_upload($ns,$auth,$file=false){
return $res; return $res;
} }
/**
* An alternative to move_uploaded_file that copies
*
* Using copy, makes sure any setgid bits on the media directory are honored
*
* @see move_uploaded_file()
* @param string $from
* @param string $to
* @return bool
*/
function copy_uploaded_file($from, $to){
if(!is_uploaded_file($from)) return false;
$ok = copy($from, $to);
@unlink($from);
return $ok;
}
/** /**
* This generates an action event and delegates to _media_upload_action(). * This generates an action event and delegates to _media_upload_action().
* Action plugins are allowed to pre/postprocess the uploaded file. * Action plugins are allowed to pre/postprocess the uploaded file.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment