From da1493b95a2f0b5000a487ae373c9318c58d0b2d Mon Sep 17 00:00:00 2001 From: Cash Costello Date: Sun, 24 Oct 2010 21:08:27 +0000 Subject: partial implementation of flash uploader --- actions/ajax_upload.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ actions/upload.php | 33 +++++++-------------------------- 2 files changed, 54 insertions(+), 26 deletions(-) create mode 100644 actions/ajax_upload.php (limited to 'actions') 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 @@ +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); } -- cgit v1.2.3