Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 60 additions & 16 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ function. Please read the notes above each variable for details on what they cha
// Set to true to show thumbnail previews of any images
public $showThumbnails = true;

// Set to true to show an audio player for audio files
public $showAudio = true;

// Set to true to allow new directories to be created.
public $enableDirectoryCreation = true;

Expand Down Expand Up @@ -165,6 +168,25 @@ function. Please read the notes above each variable for details on what they cha
'image/bmp'
);

private $__audioMimeTypes = array(
'audio/basic',
'auido/L24',
'audio/mid',
'audio/mpeg',
'audio/mp4',
'audio/x-aiff',
'audio/x-mpegurl',
'audio/vnd.rn-realaudio',
'audio/ogg',
'audio/vorbis',
'audio/vnd.wav',
);

private $__audioExtensions = array(
'mp3',
'ogg',
);

private $__currentDirectory = null;

private $__fileList = array();
Expand Down Expand Up @@ -681,6 +703,8 @@ private function __getFileType($filePath, $relativePath = null) {

$filePathInfo = pathinfo($filePath);

$extension = (isset($filePathInfo['extension']) ? $filePathInfo['extension'] : null);

$fileSize = filesize($filePath);

$fileModified = filemtime($filePath);
Expand All @@ -692,22 +716,28 @@ private function __getFileType($filePath, $relativePath = null) {
$filePreview = true;
}

return array(
'name' => $filePathInfo['basename'],
'extension' => (isset($filePathInfo['extension']) ? $filePathInfo['extension'] : null),
'dir' => $filePathInfo['dirname'],
'path' => $filePath,
'relativePath' => $relativePath,
'size' => $this->__formatSize($fileSize),
'size_bytes' => $fileSize,
'modified' => $fileModified,
'type' => 'file',
'mime' => $type,
'url' => $this->__getUrl($filePathInfo['basename']),
'preview' => $filePreview,
'target' => ($this->openLinksInNewTab ? '_blank' : '_parent')
);
}
$fileAudio = false;
if ($this->__supportsAudio($type, $extension) && $this->showAudio) {
$fileAudio = true;
}

return array(
'name' => $filePathInfo['basename'],
'extension' => $extension,
'dir' => $filePathInfo['dirname'],
'path' => $filePath,
'relativePath' => $relativePath,
'size' => $this->__formatSize($fileSize),
'size_bytes' => $fileSize,
'modified' => $fileModified,
'type' => 'file',
'mime' => $type,
'url' => $this->__getUrl($filePathInfo['basename']),
'preview' => $filePreview,
'audio' => $fileAudio,
'target' => ($this->openLinksInNewTab ? '_blank' : '_parent')
);
}

private function __supportsPreviews($type) {
if (in_array($type, $this->__previewMimeTypes)) {
Expand All @@ -716,6 +746,13 @@ private function __supportsPreviews($type) {
return false;
}

private function __supportsAudio($type, $extension) {
if (in_array($type, $this->__audioMimeTypes) || in_array($extension, $this->__audioExtensions)) {
return true;
}
return false;
}

/**
* __getUrl
*
Expand Down Expand Up @@ -1091,6 +1128,13 @@ function pr($data, $die = false) {
<span class="preview"><img src="?preview=<?php echo $file['relativePath']; ?>"><i class="preview_icon"></i></span>
<?php endif; ?>

<?php if (isset($file['audio']) && $file['audio']): ?>
<br>
<audio controls>
<source src="<?php echo $file['relativePath']; ?>">
</audio>
<?php endif; ?>

<?php if ($listing->enableFileDeletion == true): ?>
<a href="?deleteFile=<?php echo urlencode($file['relativePath']); ?>" class="pull-right btn btn-danger btn-xs" onclick="return confirm('Are you sure?')">Delete</a>
<?php endif; ?>
Expand Down