From 624f8ae36dc7f61db07da30644e2ca88b0a0de5e Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Wed, 6 Jun 2012 00:22:03 +0200 Subject: [PATCH] Also use OC_Cache here. --- apps/contacts/ajax/oc_photo.php | 18 ++++++------------ 1 file 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); } ?> -- 2.39.5