ajax_upload.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Elgg single upload action for flash/ajax uploaders
  4. */
  5. elgg_load_library('tidypics:upload');
  6. $album_guid = (int) get_input('album_guid');
  7. $file_var_name = get_input('file_var_name', 'Image');
  8. $batch = get_input('batch');
  9. $album = get_entity($album_guid);
  10. if (!$album) {
  11. echo elgg_echo('tidypics:baduploadform');
  12. exit;
  13. }
  14. // probably POST limit exceeded
  15. if (empty($_FILES)) {
  16. trigger_error('Tidypics warning: user exceeded post limit on image upload', E_USER_WARNING);
  17. register_error(elgg_echo('tidypics:exceedpostlimit'));
  18. exit;
  19. }
  20. $file = $_FILES[$file_var_name];
  21. $image = new TidypicsImage();
  22. $image->container_guid = $album->getGUID();
  23. $image->setMimeType($file['type']);
  24. $image->access_id = $album->access_id;
  25. $image->batch = $batch;
  26. try {
  27. $result = $image->save($file);
  28. } catch (Exception $e) {
  29. // remove the bits that were saved
  30. $image->delete();
  31. $result = false;
  32. echo $e->getMessage();
  33. }
  34. if ($result) {
  35. $album->prependImageList(array($image->guid));
  36. if (elgg_get_plugin_setting('img_river_view', 'tidypics') === "all") {
  37. elgg_create_river_item(array('view' => 'river/object/image/create',
  38. 'action_type' => 'create',
  39. 'subject_guid' => $image->getOwnerGUID(),
  40. 'object_guid' => $image->getGUID(),
  41. ));
  42. }
  43. }
  44. exit;