chiro-canto/public/upload/submitmetadata.php

122 lines
3.8 KiB
PHP

<?php
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
$target_dir = $root."/storage/records/";
$fileName = $_FILES['file']['name'];
$target_file = $target_dir.basename($_FILES['file']['name']);
$uploadOk = 1;
$fileSize = $_FILES['file']['size'];
$temp = explode('.', $fileName);
$fileExtension = strtolower(end($temp));
$_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";
}
if ($fileSize > 10*1024*1024)
{
$_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 :
exec("python $root./src/spectro_cli.py ".$_FILES['file']['name']);
} else {
echo "Sorry, there was an error uploading your file";
}
$_SESSION['observation']['file'] = basename($_FILES['file']['name']);
$_SESSION['error_msg'] = "";
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'] = "";
}
if (isset($_POST['recording-license']))
{
$_SESSION['observation']['license'] = $_POST['recording-license'];
setcookie('license', $_SESSION['observation']['license'], time() + 86400 * 365.2, "/");
} else
{
$_SESSION['error_msg'] .= "Incorrect license\n";
}
if (isset($_POST['name']))
{
$_SESSION['observation']['recordist-name'] = $_POST['name'];
setcookie('name', $_SESSION['observation']['name'], time() + 86400 * 365.2, "/");
} 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');
}