PHD Project - Driver energy prediction
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

52 lines
1.3 KiB

<?php
require('header_auth.php');
header_auth('Qnb7jfeGZM');
require('http_errors.php');
if (empty($_FILES['file'])) {
HttpResponse::bad_request()->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);
}
}