. * */ // Init owncloud // Check if we are a user OC_JSON::checkLoggedIn(); OC_Util::checkAppEnabled('user_migrate'); // Which operation if( $_GET['operation']=='create' ){ $uid = !empty( $_POST['uid'] ) ? $_POST['uid'] : OC_User::getUser(); if( $uid != OC_User::getUser() ){ // Needs to be admin to export someone elses account OC_JSON::error(); die(); } // Create the export zip $response = json_decode( OC_Migrate::export( $uid ) ); if( !$response->success ){ // Error OC_JSON::error(); die(); } else { // Save path in session $_SESSION['ocuserexportpath'] = $response->data; } OC_JSON::success(); die(); } else if( $_GET['operation']=='download' ){ // Download the export $path = isset( $_SESSION['ocuserexportpath'] ) ? $_SESSION['ocuserexportpath'] : false; if( !$path ){ OC_JSON::error(); } header("Content-Type: application/zip"); header("Content-Disposition: attachment; filename=" . basename($path)); header("Content-Length: " . filesize($path)); @ob_end_clean(); readfile($path); unlink( $path ); $_SESSION['ocuserexportpath'] = ''; }