Changed upload logic.

This commit is contained in:
Maxim Stewart 2018-04-18 16:25:51 -05:00
parent 39c64b4516
commit e0097e173e
3 changed files with 14 additions and 11 deletions

View File

@ -1,5 +1,6 @@
<?php <?php
$MPLAYER_WH = " -xy 1600 -geometry 50%:50% ";
$MEDIAPLAYER = "mplayer"; $MEDIAPLAYER = "mplayer";
$MUSICPLAYER = "/opt/deadbeef/bin/deadbeef"; $MUSICPLAYER = "/opt/deadbeef/bin/deadbeef";
$IMGVIEWER = "mirage"; $IMGVIEWER = "mirage";

View File

@ -5,7 +5,7 @@ function openFile($FILE) {
$EXTNSN = strtolower(pathinfo($FILE, PATHINFO_EXTENSION)); $EXTNSN = strtolower(pathinfo($FILE, PATHINFO_EXTENSION));
if (preg_match('(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg)', $EXTNSN) === 1) { if (preg_match('(mkv|avi|flv|mov|m4v|mpg|wmv|mpeg)', $EXTNSN) === 1) {
shell_exec($MEDIAPLAYER . " \"" . $FILE . "\" > /dev/null &"); shell_exec($MEDIAPLAYER . $MPLAYER_WH . "\"" . $FILE . "\" > /dev/null &");
} else if (preg_match('(png|jpg|jpeg|gif)', $EXTNSN) === 1) { } else if (preg_match('(png|jpg|jpeg|gif)', $EXTNSN) === 1) {
shell_exec($IMGVIEWER . ' "' . $FILE . '" > /dev/null &'); shell_exec($IMGVIEWER . ' "' . $FILE . '" > /dev/null &');
} else if (preg_match('(psf|mp3|ogg|flac)', $EXTNSN) === 1) { } else if (preg_match('(psf|mp3|ogg|flac)', $EXTNSN) === 1) {

View File

@ -15,8 +15,13 @@ function uploadFiles($targetDir) {
// Check if file already exists // Check if file already exists
$targetFile = $targetDir . $fileName; $targetFile = $targetDir . $fileName;
if (file_exists($targetFile)) { if (file_exists($targetFile)) {
unlink($targetFile); if (is_file($targetFile)) {
echo "<span class='warnning'>Server: [Warnning] --> This file already exists. Overwriting it.</span>"; unlink($targetFile);
echo "<span class='warnning'>Server: [Warnning] --> This file already exists. Overwriting it.</span>";
} else {
echo "<span class='warnning'>Server: [Warnning] --> This file might be a directory. Or, no files were submitted for uploading.</span>";
$uploadOk = 0;
}
} }
// Check file size // Check file size
@ -40,22 +45,19 @@ function uploadFiles($targetDir) {
// $uploadOk = 0; // $uploadOk = 0;
// } // }
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "<span class='error'>Server: [Error] --> Your file " . $fileName . " was not uploaded.</span>";
// if everything is ok, try to upload file // if everything is ok, try to upload file
} else { if ($uploadOk !== 0) {
if (move_uploaded_file($fileTmpName, $targetFile)) { if (move_uploaded_file($fileTmpName, $targetFile)) {
echo "<span class='success'>Server: [Success] --> The file " . $fileName . " has been uploaded.</span>"; echo "<span class='success'>Server: [Success] --> The file " . $fileName . " has been uploaded.</span>";
} else {
echo "<span class='error'>Server: [Error] --> File not uploaded for the above reason(s).</span>";
} }
} else {
echo "<span class='error'>Server: [Error] --> Your file " . $fileName . " was not uploaded.</span>";
} }
} }
echo "</body></html>"; echo "</body></html>";
// Prompt an update clint side when sse checks that there is updateListing. // Prompt an update clint side when sse checks that there is updateListing.
$myfile = fopen("../vars.txt", "w+"); $myfile = fopen("resources/vars.txt", "w+");
$txt = "updateListing"; $txt = "updateListing";
fwrite($myfile, $txt); fwrite($myfile, $txt);
fclose($myfile); fclose($myfile);
@ -63,7 +65,7 @@ function uploadFiles($targetDir) {
// Check access type. // Check access type.
chdir("../../"); chdir("../../");
if(isset($_POST["UploadFiles"])) { if(isset($_POST["UploadFiles"]) && isset($_POST["DIRPATHUL"])) {
uploadFiles($_POST["DIRPATHUL"]); uploadFiles($_POST["DIRPATHUL"]);
} else { } else {
echo "<span style='color:rgb(255, 0, 0);'>Server: [Error] --> Incorrect access attempt!</span>"; echo "<span style='color:rgb(255, 0, 0);'>Server: [Error] --> Incorrect access attempt!</span>";