diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-06-06 00:22:03 +0200 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-06-06 01:06:13 +0200 |
commit | 624f8ae36dc7f61db07da30644e2ca88b0a0de5e (patch) | |
tree | 0aea14e64729189cc5534e01192494859a6ba725 /apps | |
parent | 80de23d08b8021709adceac626bbac5aab45d86a (diff) | |
download | nextcloud-server-624f8ae36dc7f61db07da30644e2ca88b0a0de5e.tar.gz nextcloud-server-624f8ae36dc7f61db07da30644e2ca88b0a0de5e.zip |
Also use OC_Cache here.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/contacts/ajax/oc_photo.php | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/apps/contacts/ajax/oc_photo.php b/apps/contacts/ajax/oc_photo.php index 184217f2b72..ea25ebf1763 100644 --- a/apps/contacts/ajax/oc_photo.php +++ b/apps/contacts/ajax/oc_photo.php @@ -20,8 +20,6 @@ * */ // Check if we are a user -// Firefox and Konqueror tries to download application/json for me. --Arthur -OCP\JSON::setContentTypeHeader('text/plain'); OCP\JSON::checkLoggedIn(); OCP\JSON::checkAppEnabled('contacts'); function bailOut($msg) { @@ -29,9 +27,6 @@ function bailOut($msg) { OCP\Util::writeLog('contacts','ajax/oc_photo.php: '.$msg, OCP\Util::ERROR); exit(); } -function debug($msg) { - OCP\Util::writeLog('contacts','ajax/oc_photo.php: '.$msg, OCP\Util::DEBUG); -} if(!isset($_GET['id'])) { bailOut(OC_Contacts_App::$l10n->t('No contact ID was submitted.')); @@ -42,31 +37,30 @@ if(!isset($_GET['path'])) { } $localpath = OC_Filesystem::getLocalFile($_GET['path']); -$tmpfname = tempnam(get_temp_dir(), "occOrig"); +$tmpkey = 'contact-photo-'.$_GET['id']; if(!file_exists($localpath)) { bailOut(OC_Contacts_App::$l10n->t('File doesn\'t exist:').$localpath); } -file_put_contents($tmpfname, file_get_contents($localpath)); $image = new OC_Image(); if(!$image) { bailOut(OC_Contacts_App::$l10n->t('Error loading image.')); } -if(!$image->loadFromFile($tmpfname)) { +if(!$image->loadFromFile($localpath)) { bailOut(OC_Contacts_App::$l10n->t('Error loading image.')); } if($image->width() > 400 || $image->height() > 400) { $image->resize(400); // Prettier resizing than with browser and saves bandwidth. } if(!$image->fixOrientation()) { // No fatal error so we don't bail out. - debug('Couldn\'t save correct image orientation: '.$tmpfname); + OCP\Util::writeLog('contacts','ajax/oc_photo.php: Couldn\'t save correct image orientation: '.$localpath, OCP\Util::DEBUG); } -if($image->save($tmpfname)) { - OCP\JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpfname))); +if(OC_Cache::set($tmpkey, $image->data(), 600)) { + OCP\JSON::success(array('data' => array('id'=>$_GET['id'], 'tmp'=>$tmpkey))); exit(); } else { - bailOut('Couldn\'t save temporary image: '.$tmpfname); + bailOut('Couldn\'t save temporary image: '.$tmpkey); } ?> |