aboutsummaryrefslogtreecommitdiff
path: root/actions/ajax_upload.php
blob: 1f5588197697a3f573897b4ac86045631f292dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?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;
}

// probably POST limit exceeded
if (empty($_FILES)) {
	echo 'Image was too large';
	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'];

$mime = tp_upload_get_mimetype($name);
if ($mime == 'unknown') {
	echo 'Not an image';
	exit;
}

$image = new TidypicsImage();
$image->container_guid = $album_guid;
$image->setMimeType($mime);
$image->simpletype = "image";
$image->access_id = $album->access_id;
$image->title = substr($name, 0, strrpos($name, '.'));
$image->batch = get_input('batch');
$result = $image->save();

$image->setOriginalFilename($name);
$image->saveImageFile($temp_file, $file_size);

$image->extractExifData();
$image->saveThumbnails($image_lib);

$album->prependImageList(array($image->guid));


if (get_plugin_setting('img_river_view', 'tidypics') === "all") {
	add_to_river('river/object/image/create', 'create', $image->owner_guid, $image->guid);
}

echo "success";
exit;