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 /lib/exe | |
parent | 0eca67c2d107d04c48f193b1ff5c84653d064693 (diff) | |
download | rpg-2d6cc64fdb73879f54aa25b2122f36631c654e3c.tar.gz rpg-2d6cc64fdb73879f54aa25b2122f36631c654e3c.tar.bz2 |
issue #44, #52 media_upload reused, error handling
Diffstat (limited to 'lib/exe')
-rw-r--r-- | lib/exe/ajax.php | 63 |
1 files changed, 11 insertions, 52 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php index 7a4cea360..aa07fe7b0 100644 --- a/lib/exe/ajax.php +++ b/lib/exe/ajax.php @@ -249,65 +249,24 @@ function ajax_mediadiff(){ } function ajax_mediaupload(){ - global $NS; + global $NS, $MSG; + $NS = $_REQUEST['ns']; $AUTH = auth_quickaclcheck("$NS:*"); if($AUTH >= AUTH_UPLOAD) { io_createNamespace("$NS:xxx", 'media'); } - if($_FILES['qqfile']['error']){ - unset($_FILES['qqfile']); - } - - if($_FILES['qqfile']['tmp_name']){ - $id = $_REQUEST['file_name']; - if (!$id) $id = $_FILES['qqfile']['name']; - $file = $_FILES['qqfile']['tmp_name']; - list($ext,$mime,$dl) = mimetype($id); - - $res = media_save( - array('name' => $file, - 'mime' => $mime, - 'ext' => $ext), - $NS.':'.$id, - $_REQUEST['ow'], - $AUTH, - 'move_uploaded_file' - ); - if (!is_array($res)) { - $result = array('success'=>true); - } - } + if ($_FILES['qqfile']['error']) unset($_FILES['qqfile']); + if ($_FILES['qqfile']['tmp_name']) $res = media_upload($NS, $AUTH, $_FILES['qqfile']); + if (isset($_GET['qqfile'])) $res = media_upload_xhr($NS, $AUTH); + if ($res) $result = array('success'=>true); - if (isset($_GET['qqfile'])) { - $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)) { - $result = array('success'=>true); + if (!$result) { + $error = ''; + if (isset($MSG)) { + foreach($MSG as $msg) $error .= $msg['msg']; } + $result = array('error'=> $msg['msg']); } - if (!$result) $result = array('error'=> 'Could not save uploaded file.'); echo htmlspecialchars(json_encode($result), ENT_NOQUOTES); } |