chiro-canto/public/home/last-uploaded-file.php

41 lines
1.2 KiB
PHP
Raw Normal View History

2021-03-30 10:52:22 +02:00
<?php
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require "$root/database/credentials.php";
// Connect the database
try {
$db = new PDO("mysql:host=$host;dbname=$database;charset=utf8",
$user,
$password,
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
} catch (Exception $e) {
die("Error : ".$e->getMessage());
}
2021-03-31 08:38:30 +02:00
$req = $db->prepare('SELECT id, recordist_name, file_name, license, species, sound_type, date, time FROM `records` ORDER BY `entry_timestamp` DESC LIMIT 1');
2021-03-30 10:52:22 +02:00
$req->execute();
if ($data = $req->fetch())
{
?>
<div class="sound">
<h3><?=$data['file_name']?></h3>
<h4><em><?=$data['species']?></em></h4>
<p>Recorded on <?=$data['date']?> at <?=$data['time']?></p>
2021-03-31 08:38:30 +02:00
<?php
if (file_exists($root."/storage/spectrograms/".$data['file_name'].'.png'))
{
?>
<img id="spectrogram" src="<?="/storage/spectrograms/".$data['file_name'].'.png'?>" alt="bat sound spectrogram">
<?php
}
?>
<br>
2021-03-30 10:52:22 +02:00
<audio src="<?="../storage/records/".$data['file_name']?>" controls></audio>
<p><?=$data['license']?> <?=$data['recordist_name']?></p>
</div>
<?php
} else {
echo "Error fetch.";
}
?>