set_and_exit(); } try { define('TARGET_DIR', 'computed_uploads/'); define('GZREAD_BUFFER_SIZE', 4096); $gz_target_filename = TARGET_DIR . basename($_FILES['file']['name']); if (!move_uploaded_file($_FILES['file']['tmp_name'], $gz_target_filename)) { HttpResponse::internal_server_error()->set_and_exit(); } $gz_fd = gzopen($gz_target_filename, 'rb'); $ungzip_target_filename = str_replace('.gz', '', str_replace('.gzip', '', $gz_target_filename)); $ungzip_fd = fopen($ungzip_target_filename, 'wb'); while (!gzeof($gz_fd)) { fwrite($ungzip_fd, gzread($gz_fd, GZREAD_BUFFER_SIZE)); } unlink($gz_target_filename); $clear_before = isset($_GET['clear']) && $_GET['clear'] == 1;; require('save_computed_data_to_db.php'); if (isset($_POST['userdata'])) { save_computed_data_to_db($ungzip_target_filename, $clear_before, $_POST['userdata']); } else { save_computed_data_to_db($ungzip_target_filename, $clear_before); } } catch (Exception $e) { error_log($e->getMessage()); HttpResponse::internal_server_error()->set_and_exit(); } finally { if (isset($gz_fd)) { gzclose($gz_fd); } if (isset($ungzip_fd)) { fclose($ungzip_fd); } }