diff options
author | Cash Costello <cash.costello@gmail.com> | 2010-10-24 21:08:27 +0000 |
---|---|---|
committer | Cash Costello <cash.costello@gmail.com> | 2010-10-24 21:08:27 +0000 |
commit | da1493b95a2f0b5000a487ae373c9318c58d0b2d (patch) | |
tree | a339b053ade9fb15a1717bdf248a59afc9b3d239 /actions | |
parent | 5161b1c8fdc8ff69005f864a89127fc18db6d4ed (diff) | |
download | elgg-da1493b95a2f0b5000a487ae373c9318c58d0b2d.tar.gz elgg-da1493b95a2f0b5000a487ae373c9318c58d0b2d.tar.bz2 |
partial implementation of flash uploader
Diffstat (limited to 'actions')
-rw-r--r-- | actions/ajax_upload.php | 47 | ||||
-rw-r--r-- | actions/upload.php | 33 |
2 files changed, 54 insertions, 26 deletions
diff --git a/actions/ajax_upload.php b/actions/ajax_upload.php new file mode 100644 index 000000000..3d44df199 --- /dev/null +++ b/actions/ajax_upload.php @@ -0,0 +1,47 @@ +<?php +/** + * Elgg single upload action for flash/ajax uploaders + * + */ + +include_once dirname(dirname(__FILE__)) . "/lib/upload.php"; + +$album_guid = (int) get_input('album_guid'); +$file_var_name = get_input('file_var_name', 'Image'); + +$album = get_entity($album_guid); +if (!$album) { + exit; +} + +if (empty($_FILES)) { + exit; +} + +$image_lib = get_plugin_setting('image_lib', 'tidypics'); +if (!$image_lib) { + $image_lib = "GD"; +} + +$temp_file = $_FILES['Image']['tmp_name']; +$name = $_FILES['Image']['name']; +$file_size = $_FILES['Image']['size']; + +$image = new TidypicsImage(); +$image->container_guid = $album_guid; +$image->setMimeType(tp_upload_get_mimetype($name)); +$image->simpletype = "image"; +$image->access_id = $album->access_id; +$image->title = substr($name, 0, strrpos($name, '.')); +$image_guid = $image->save(); + +$image->setOriginalFilename($name); +$image->saveImageFile($temp_file, $file_size); + +$image->extractExifData(); +$image->saveThumbnails($image_lib); + +$album->prependImageList(array($image->guid)); + +echo "1"; +exit;
\ No newline at end of file diff --git a/actions/upload.php b/actions/upload.php index 2d7b311bb..8dae85277 100644 --- a/actions/upload.php +++ b/actions/upload.php @@ -16,17 +16,6 @@ if (!$album) { forward($_SERVER['HTTP_REFERER']); } -$maxfilesize = (float) get_plugin_setting('maxfilesize','tidypics'); -if (!$maxfilesize) { - $maxfilesize = 5; // default to 5 MB if not set -} -$maxfilesize = 1024 * 1024 * $maxfilesize; // convert to bytes from MBs - -$quota = get_plugin_setting('quota','tidypics'); -$quota = 1024 * 1024 * $quota; -$image_repo_size_md = get_metadata_byname($album->container_guid, "image_repo_size"); -$image_repo_size = (int)$image_repo_size_md->value; - $image_lib = get_plugin_setting('image_lib', 'tidypics'); if (!$image_lib) { $image_lib = "GD"; @@ -88,16 +77,14 @@ foreach($_FILES as $key => $sent_file) { } // check quota - if ($quota) { - if ($image_repo_size + $sent_file['size'] > $quota) { - array_push($not_uploaded, $sent_file['name']); - array_push($error_msgs, elgg_echo('tidypics:exceed_quota')); - continue; - } + if (!tp_upload_check_quota($sent_file['size'], get_loggedin_userid())) { + array_push($not_uploaded, $sent_file['name']); + array_push($error_msgs, elgg_echo('tidypics:exceed_quota')); + continue; } // make sure file does not exceed memory limit - if ($sent_file['size'] > $maxfilesize) { + if (!tp_upload_check_max_size($sent_file['size'])) { array_push($not_uploaded, $sent_file['name']); array_push($error_msgs, elgg_echo('tidypics:image_mem')); continue; @@ -120,8 +107,6 @@ foreach($_FILES as $key => $sent_file) { $file->access_id = $access_id; //$file->title = substr($name, 0, strrpos($name, '.')); - $file->setOriginalFilename($name); - $file->saveImageFile(get_uploaded_file($key)); $result = $file->save(); if (!$result) { @@ -130,6 +115,8 @@ foreach($_FILES as $key => $sent_file) { continue; } + $file->setOriginalFilename($name); + $file->saveImageFile($sent_file['tmp_name'], $sent_file['size']); $file->extractExifData(); $file->saveThumbnails($image_lib); @@ -140,9 +127,6 @@ foreach($_FILES as $key => $sent_file) { array_push($uploaded_images, $file->guid); - // update user/group size for checking quota - $image_repo_size += $sent_file['size']; - // plugins can register to be told when a new image has been uploaded trigger_elgg_event('upload', 'tp_image', $file); @@ -192,9 +176,6 @@ if (count($uploaded_images) && $img_river_view == "1") { add_to_river('river/object/image/create', 'create', $file_for_river->getObjectOwnerGUID(), $file_for_river->getGUID()); } -// update image repo size -create_metadata($album->container_guid, "image_repo_size", $image_repo_size, 'integer', $album->container_guid); - if (count($uploaded_images) > 0) { $album->prependImageList($uploaded_images); } |