diff options
author | Kate Arzamastseva <pshns@ukr.net> | 2011-08-12 12:50:34 +0300 |
---|---|---|
committer | Kate Arzamastseva <pshns@ukr.net> | 2011-08-12 12:50:34 +0300 |
commit | 2d6cc64fdb73879f54aa25b2122f36631c654e3c (patch) | |
tree | 4ba695270dbd3062550ceb4aefc33a3572d6b187 /inc/media.php | |
parent | 0eca67c2d107d04c48f193b1ff5c84653d064693 (diff) | |
download | rpg-2d6cc64fdb73879f54aa25b2122f36631c654e3c.tar.gz rpg-2d6cc64fdb73879f54aa25b2122f36631c654e3c.tar.bz2 |
issue #44, #52 media_upload reused, error handling
Diffstat (limited to 'inc/media.php')
-rw-r--r-- | inc/media.php | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/inc/media.php b/inc/media.php index 768026b54..abdb33bcb 100644 --- a/inc/media.php +++ b/inc/media.php @@ -243,19 +243,56 @@ function media_delete($id,$auth){ } /** + * Handle file uploads via XMLHttpRequest + * + * @return mixed false on error, id of the new file on success + */ +function media_upload_xhr($ns,$auth){ + $id = $_GET['qqfile']; + list($ext,$mime,$dl) = mimetype($id); + $input = fopen("php://input", "r"); + $temp = tmpfile(); + $realSize = stream_copy_to_stream($input, $temp); + fclose($input); + if ($realSize != (int)$_SERVER["CONTENT_LENGTH"]) return false; + if (!($tmp = io_mktmpdir())) return false; + $path = $tmp.'/'.$id; + $target = fopen($path, "w"); + fseek($temp, 0, SEEK_SET); + stream_copy_to_stream($temp, $target); + fclose($target); + $res = media_save( + array('name' => $path, + 'mime' => $mime, + 'ext' => $ext), + $ns.':'.$id, + (($_REQUEST['ow'] == 'true') ? true : false), + $auth, + 'copy' + ); + unlink($path); + if ($tmp) dir_delete($tmp); + if (is_array($res)) { + msg($res[0], $res[1]); + return false; + } + return $res; +} + +/** * Handles media file uploads * * @author Andreas Gohr <andi@splitbrain.org> * @author Michael Klier <chi@chimeric.de> * @return mixed false on error, id of the new file on success */ -function media_upload($ns,$auth){ +function media_upload($ns,$auth,$file=false){ if(!checkSecurityToken()) return false; global $lang; // get file and id $id = $_POST['mediaid']; - $file = $_FILES['upload']; + if (!$file) $file = $_FILES['upload']; if(empty($id)) $id = $file['name']; // check for errors (messages are done in lib/exe/mediamanager.php) |