public static function postAvatar($args) { \OC_JSON::checkLoggedIn(); \OC_JSON::callCheck(); $user = \OC_User::getUser(); if (isset($_POST['path'])) { $path = stripslashes($_POST['path']); $view = new \OC\Files\View('/' . $user . '/files'); $fileInfo = $view->getFileInfo($path); if ($fileInfo['encrypted'] === true) { $fileName = $view->toTmpFile($path); } else { $fileName = $view->getLocalFile($path); } } elseif (!empty($_FILES)) { $files = $_FILES['files']; if ($files['error'][0] === 0 && is_uploaded_file($files['tmp_name'][0]) && !\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])) { \OC\Cache::set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200); $view = new \OC\Files\View('/' . $user . '/cache'); $fileName = $view->getLocalFile('avatar_upload'); unlink($files['tmp_name'][0]); } } else { $l = new \OC_L10n('core'); \OC_JSON::error(array("data" => array("message" => $l->t("No image or file provided")))); return; } try { $image = new \OC_Image(); $image->loadFromFile($fileName); $image->fixOrientation(); if ($image->valid()) { \OC\Cache::set('tmpavatar', $image->data(), 7200); \OC_JSON::error(array("data" => "notsquare")); } else { $l = new \OC_L10n('core'); $mimeType = $image->mimeType(); if ($mimeType !== 'image/jpeg' && $mimeType !== 'image/png') { \OC_JSON::error(array("data" => array("message" => $l->t("Unknown filetype")))); } if (!$image->valid()) { \OC_JSON::error(array("data" => array("message" => $l->t("Invalid image")))); } } } catch (\Exception $e) { \OC_JSON::error(array("data" => array("message" => $e->getMessage()))); } }
if ($fullPath === null) { exit; } $img = trim($fullPath . '/' . $img); } else { OCP\JSON::checkLoggedIn(); $user = OCP\User::getUser(); } session_write_close(); $ownerView = new \OC\Files\View('/' . $user . '/files'); $mime = $ownerView->getMimeType($img); list($mimePart, ) = explode('/', $mime); if ($mimePart === 'image') { $fileInfo = $ownerView->getFileInfo($img); if ($fileInfo['encrypted'] === true) { $local = $ownerView->toTmpFile($img); } else { $local = $ownerView->getLocalFile($img); } $rotate = false; if (is_callable('exif_read_data')) { //don't use OCP\Image here, using OCP\Image will always cause parsing the image file $exif = @exif_read_data($local, 'IFD0'); if (isset($exif['Orientation'])) { $rotate = $exif['Orientation'] > 1; } } OCP\Response::setContentDispositionHeader(basename($img), 'attachment'); if ($rotate) { $image = new OCP\Image($local); $image->fixOrientation();