chiro-canto/public/upload/submitmetadata.php

130 lines
4.2 KiB
PHP
Raw Normal View History

2021-03-28 20:40:17 +02:00
<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
2021-03-29 12:05:53 +02:00
$target_dir = $root."/storage/records/";
2021-03-28 20:40:17 +02:00
$fileName = $_FILES['file']['name'];
$target_file = $target_dir.basename($_FILES['file']['name']);
$uploadOk = 1;
$fileSize = $_FILES['file']['size'];
2021-03-29 12:05:53 +02:00
$temp = explode('.', $fileName);
$fileExtension = strtolower(end($temp));
2021-03-28 20:40:17 +02:00
$_SESSION['error_msg'] = "Form not submitted.\n";
if (isset($_POST['submit']))
{
// /!\ Need to check if it is .wav.
$file_extension_allowed = ['wav'];
if (! in_array($fileExtension, $file_extension_allowed))
{
$_SESSION['error_msg'] .= "This file extension is not allowed; please upload a WAV file.\n";
}
2021-03-29 12:05:53 +02:00
if ($fileSize > 10*1024*1024)
2021-03-28 20:40:17 +02:00
{
$_SESSION['error_msg'] .= "The file size must be below 10MB. \n";
}
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file))
{
echo "The file ". htmlspecialchars(basename($_FILES['file']['name']))." has been uploaded.";
// Create a spectogram of the file :
2021-03-31 08:38:30 +02:00
exec("python3 $root./src/spectro_cli.py ".$_FILES['file']['name']);
2021-03-28 20:40:17 +02:00
} else {
echo "Sorry, there was an error uploading your file";
}
$_SESSION['observation']['file'] = basename($_FILES['file']['name']);
$_SESSION['error_msg'] = "";
2021-03-31 08:38:30 +02:00
if (isset($_POST['spchoice']))
2021-03-28 20:40:17 +02:00
{
2021-03-31 08:38:30 +02:00
if ($_POST['spchoice'] == "unknown") {
$_SESSION['observation']['species'] = "unknown";
$_SESSION['observation']['subspecies'] = "";
setcookie('species', $_SESSION['observation']['species'], time() + 86400 * 365.2, "/");
} else {
if (isset($_POST['species']))
{
$_SESSION['observation']['species'] = $_POST['species'];
setcookie('species', $_SESSION['observation']['species'], time() + 86400 * 365.2, "/");
} else
{
$_SESSION['error_msg'].= "Error, incorrect species name.\n";
}
if (isset($_POST['subspecies']))
{
$_SESSION['observation']['subspecies'] = $_POST['subspecies'];
setcookie('subspecies', $_SESSION['observation']['subspecies'], time() + 86400 * 365.2, "/");
} else
{
$_SESSION['observation']['subspecies'] = "";
}
}
2021-03-28 20:40:17 +02:00
}
if (isset($_POST['recording-license']))
{
$_SESSION['observation']['license'] = $_POST['recording-license'];
2021-03-29 12:05:53 +02:00
setcookie('license', $_SESSION['observation']['license'], time() + 86400 * 365.2, "/");
2021-03-28 20:40:17 +02:00
} else
{
$_SESSION['error_msg'] .= "Incorrect license\n";
}
if (isset($_POST['name']))
{
2021-03-30 07:31:22 +02:00
$_SESSION['observation']['recordist-name'] = $_POST['name'];
2021-03-29 12:05:53 +02:00
setcookie('name', $_SESSION['observation']['name'], time() + 86400 * 365.2, "/");
2021-03-28 20:40:17 +02:00
} else {
$_SESSION['error_msg'] .= "Incorrect Recordist Name.\n";
}
if (isset($_POST['loc-country']))
{
$_SESSION['observation']['country'] = $_POST['loc-country'];
} else
{
$_SESSION['error_msg'] .= "Incorrect Country. \n";
}
if (isset($_POST['recording-date']))
{
$_SESSION['observation']['date'] = $_POST['recording-date'];
} else
{
$_SESSION['error_msg'] .= "Incorrect date. \n";
}
if (isset($_POST['recording-time']))
{
$_SESSION['observation']['time'] = $_POST['recording-time'];
} else
{
$_SESSION['error_msg'] .= "Incorrect time. \n";
}
if (isset($_POST['sound-type-option']))
{
$_SESSION['observation']['type'] = $_POST['sound-type-option'];
} else
{
$_SESSION['error_msg'] .= "Incorrect sound type. \n";
}
if (isset($_POST['quality']))
{
$_SESSION['observation']['quality'] = $_POST['quality'];
} else
{
$_SESSION['error_msg'] .= "Incorrect quality value.\n";
}
if (isset($_POST['remarks']))
{
$_SESSION['observation']['remarks'] = $_POST['remarks'];
}
}
if ($_SESSION['error_msg'] == "")
{
header('Location: '.'index.php?step=verify');
} else{
$_SESSION['error_msg'] .= "Please try again.\n";
header('Location: '.'index.php?step=metadata');
}