Only check size if needed - should speed up the uploading.

This commit is contained in:
Michael Vogel 2016-01-28 12:28:04 +01:00
parent eba9f15daa
commit 845a769dc2

View file

@ -158,14 +158,18 @@ function wall_upload_post(&$a, $desktopmode = true) {
killme(); killme();
} }
logger("Check size of picture.", LOGGER_DEBUG);
$r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
intval($page_owner_uid)
);
$limit = service_class_fetch($page_owner_uid,'photo_upload_limit'); $limit = service_class_fetch($page_owner_uid,'photo_upload_limit');
if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { if ($limit) {
$r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
intval($page_owner_uid)
);
$size = $r[0]['total'];
} else
$size = 0;
if(($limit !== false) && (($size + strlen($imagedata)) > $limit)) {
$msg = upgrade_message(true); $msg = upgrade_message(true);
if ($r_json) { if ($r_json) {
echo json_encode(array('error'=>$msg)); echo json_encode(array('error'=>$msg));
@ -177,7 +181,6 @@ function wall_upload_post(&$a, $desktopmode = true) {
} }
logger("Picture will be processed.", LOGGER_DEBUG);
$imagedata = @file_get_contents($src); $imagedata = @file_get_contents($src);
$ph = new Photo($imagedata, $filetype); $ph = new Photo($imagedata, $filetype);
@ -212,7 +215,6 @@ function wall_upload_post(&$a, $desktopmode = true) {
$defperm = '<' . $default_cid . '>'; $defperm = '<' . $default_cid . '>';
logger("Picture will be stored", LOGGER_DEBUG);
$r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm); $r = $ph->store($page_owner_uid, $visitor, $hash, $filename, t('Wall Photos'), 0, 0, $defperm);
if(! $r) { if(! $r) {
@ -269,7 +271,6 @@ function wall_upload_post(&$a, $desktopmode = true) {
return $picture; return $picture;
} }
logger("Picture is stored.", LOGGER_DEBUG);
if ($r_json) { if ($r_json) {
echo json_encode(array('ok'=>true)); echo json_encode(array('ok'=>true));