netv-mam/upload.php
2024-09-03 10:37:30 -04:00

50 lines
1.4 KiB
PHP

<?php
// handle uploads from js frontend
ini_set("max_input_time", 6000);
ini_set("post_max_size", 0);
ini_set("upload_max_filesize", "32G");
require 'vendor/autoload.php';
$db = new SQLite3('netv-mam.sqlite');
$uploaddir = "/opt/netv-media/";
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
error_log("File upload:");
error_log(json_encode($_FILES));
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
// get media info
$ffprobe = FFMpeg\FFProbe::create();
$duration_secs = $ffprobe
->format($uploadfile)
->get('duration');
$query = "INSERT INTO media (source_path, title, duration_secs) VALUES (:source_path, 'unknown', :duration_secs)";
$statement = $db->prepare($query);
$statement->bindValue(':source_path', $uploadfile);
$statement->bindValue(':duration_secs', $duration_secs);
$result = $statement->execute();
if ($result) {
$new_media_file = array(
'id' => $db->lastInsertRowID(),
'title' => 'unknown',
'source_path' => $uploadfile,
'duration_secs' => $duration_secs,
'has_metadata' => false
);
error_log("Adding media file:");
error_log(json_encode($new_media_file));
echo(json_encode($new_media_file));
} else {
error_log("Problem inserting new media into db:");
error_log($db->lastErrorMsg());
echo("{}");
}
} else {
echo("{}");
}
?>