summaryrefslogtreecommitdiff
path: root/lib/exe/ajax.php
diff options
context:
space:
mode:
authorKate Arzamastseva <pshns@ukr.net>2011-08-04 20:32:16 +0300
committerKate Arzamastseva <pshns@ukr.net>2011-08-04 20:32:16 +0300
commit09063cc66339d6e5daa12af4896a2457c03cfaf3 (patch)
tree99902823aa8d528ac28ec1ad665561386f4316ae /lib/exe/ajax.php
parenta1a02ef6d327f2de7ffc7db57a7907465761b407 (diff)
downloadrpg-09063cc66339d6e5daa12af4896a2457c03cfaf3.tar.gz
rpg-09063cc66339d6e5daa12af4896a2457c03cfaf3.tar.bz2
issue #44 multi file uploader
Diffstat (limited to 'lib/exe/ajax.php')
-rw-r--r--lib/exe/ajax.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/exe/ajax.php b/lib/exe/ajax.php
index 20fc99de4..391e951e5 100644
--- a/lib/exe/ajax.php
+++ b/lib/exe/ajax.php
@@ -248,6 +248,88 @@ function ajax_mediadiff(){
media_diff($image, $NS, $auth);
}
+function ajax_mediaupload(){
+ global $NS;
+ $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 = $_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,
+ false,
+ $AUTH,
+ 'move_uploaded_file'
+ );
+ if (!is_array($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,
+ false,
+ $AUTH,
+ 'copy'
+ );
+ unlink($path);
+ if ($tmp) dir_delete($tmp);
+ if (!is_array($res)) {
+ $result = array('success'=>true);
+ }
+ }
+ if (!$result) $result = array('error'=> 'Could not save uploaded file.');
+ echo htmlspecialchars(json_encode($result), ENT_NOQUOTES);
+}
+
+function dir_delete($path) {
+ if (!is_string($path) || $path == "") return false;
+
+ if (is_dir($path) && !is_link($path)) {
+ if (!$dh = @opendir($path)) return false;
+
+ while ($f = readdir($dh)) {
+ if ($f == '..' || $f == '.') continue;
+ dir_delete("$path/$f");
+ }
+
+ closedir($dh);
+ return @rmdir($path);
+ } else {
+ return @unlink($path);
+ }
+
+ return false;
+}
+
/**
* Return sub index for index view
*