summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2012-07-29 12:25:32 +0200
committerAndreas Gohr <andi@splitbrain.org>2012-07-29 12:25:32 +0200
commit71f17ac4602c2b6b1e3b46130c4c6cb7c3f8702e (patch)
tree980a9b0c1abbf45938d315109cee6c7b97d37ba9
parentfa446926c63aef4f4f394967b84d20e2da0dad6d (diff)
downloadrpg-71f17ac4602c2b6b1e3b46130c4c6cb7c3f8702e.tar.gz
rpg-71f17ac4602c2b6b1e3b46130c4c6cb7c3f8702e.tar.bz2
copy not move uploaded files FS#2465
This fixes problems with setgid bits on the media directory
-rw-r--r--inc/media.php19
1 files changed, 18 insertions, 1 deletions
diff --git a/inc/media.php b/inc/media.php
index 794aab8aa..6941aa61a 100644
--- a/inc/media.php
+++ b/inc/media.php
@@ -296,7 +296,7 @@ function media_upload($ns,$auth,$file=false){
$res = media_save(array('name' => $file['tmp_name'],
'mime' => $imime,
'ext' => $iext), $ns.':'.$id,
- $INPUT->post->bool('ow'), $auth, 'move_uploaded_file');
+ $INPUT->post->bool('ow'), $auth, 'copy_uploaded_file');
if (is_array($res)) {
msg($res[0], $res[1]);
return false;
@@ -305,6 +305,23 @@ function media_upload($ns,$auth,$file=false){
}
/**
+ * 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().
* Action plugins are allowed to pre/postprocess the uploaded file.
* (The triggered event is preventable.)